Unit 1: Computer Languages - Subjective Questions
CSE111 — Orientation To Computing • Practice Questions with Detailed Answers
20 questions
Define machine language. Explain its main characteristics, advantages, and limitations.
Machine language is the lowest-level programming language understood and executed directly by a computer's processor. Its instructions are represented using binary digits, namely 0 and 1.
Main characteristics:
- Instructions are written in binary form.
- Each instruction usually contains an operation code and one or more operand addresses.
- It is specific to a particular processor architecture.
- It does not require a translator before execution.
Advantages:
- It is executed directly by the CPU.
- Programs can run very quickly.
- It provides direct control over hardware resources.
Limitations:
- Binary instructions are difficult to read, write, and remember.
- Programming and debugging are time-consuming.
- Errors are common and difficult to locate.
- A program written for one processor may not work on another processor.
Thus, machine language provides maximum hardware control but has poor readability, portability, and ease of development.
What is assembly language? Describe how it improves upon machine language.
Assembly language is a low-level programming language that represents machine instructions using symbolic operation codes called mnemonics and meaningful names for memory locations.
For example, an assembly instruction may be written as ADD R1, R2 instead of a long binary sequence.
Improvements over machine language:
- Mnemonics such as
ADD,SUB,MOV, andJMPare easier to understand than binary codes. - Symbolic names can be used for variables, registers, and memory locations.
- Programs are easier to write, modify, and debug.
- The chances of making errors are lower than in machine-language programming.
However, assembly language remains machine-dependent. An assembler must translate it into machine code before the processor can execute it. Therefore, it improves readability and productivity but does not provide the portability of a high-level language.
Explain the meaning and important features of a high-level programming language.
A high-level programming language is a language designed to allow programmers to write instructions using English-like words, mathematical notation, and structured statements rather than hardware-specific binary codes.
Examples include C, C++, Java, Python, and BASIC.
Important features:
- Readability: Programs are easier for humans to read and understand.
- Portability: The same source program can often run on different computers with little or no modification.
- Abstraction: Hardware details such as memory addresses and processor instructions are largely hidden.
- Productivity: Complex programs can be developed using fewer instructions.
- Maintainability: Programs are easier to test, debug, modify, and document.
- Rich facilities: High-level languages provide variables, functions, loops, conditions, and data structures.
A high-level program cannot normally be executed directly by the CPU. It must first be translated into machine code by a compiler or an interpreter.
Compare machine language, assembly language, and high-level language.
The three categories of computer languages can be compared as follows:
| Basis | Machine Language | Assembly Language | High-Level Language |
|---|---|---|---|
| Representation | Binary digits such as 0 and 1 |
Mnemonics and symbolic addresses | English-like statements and expressions |
| Translator | Not required | Assembler | Compiler or interpreter |
| Hardware dependence | Completely machine-dependent | Machine-dependent | Mostly machine-independent |
| Ease of programming | Very difficult | Easier than machine language | Relatively easy |
| Execution control | Direct control of hardware | Strong hardware control | Hardware details are abstracted |
| Portability | Very low | Very low | High |
| Debugging | Very difficult | Moderately difficult | Comparatively easy |
| Development time | Long | Moderate | Shorter |
| Examples | Binary CPU instructions | MOV, ADD, SUB |
C, Java, Python |
Conclusion: Machine language offers direct execution, assembly language improves symbolic readability, and high-level language provides portability, abstraction, and faster software development.
Define a language translator. Why are translators required in computer programming?
A language translator is system software that converts a program written in one programming language into an equivalent program in another language, usually machine language.
Translators are required because the CPU can directly understand only machine instructions. Programs written in assembly or high-level languages must therefore be converted before execution.
Major types of translators:
- Assembler: Converts assembly language into machine or object code.
- Compiler: Translates an entire high-level source program before execution.
- Interpreter: Translates and executes a high-level program one statement at a time.
Other functions of translators may include:
- Detecting and reporting syntax errors.
- Checking whether language rules are followed.
- Generating object or machine code.
- Optimizing instructions for better performance.
- Providing diagnostic information to the programmer.
Thus, translators form an essential bridge between human-readable source programs and the machine-readable instructions executed by a processor.
What is a compiler? Explain its major functions.
A compiler is a language translator that reads an entire program written in a high-level language and translates it into object code or machine code before the program is executed.
Major functions of a compiler:
- Reads and analyzes the complete source program.
- Checks the source code for lexical, syntax, and semantic errors.
- Produces diagnostic messages when errors are found.
- Converts valid source instructions into target or object code.
- May optimize the generated code to improve speed or reduce memory use.
- Creates information required by the linker to combine object files and libraries.
If compilation is successful, the object code is linked with necessary library routines to create an executable file. The executable can then be run repeatedly without recompiling it, provided the source program has not changed.
Compiled programs generally execute quickly because translation is completed before execution.
Explain how an interpreter translates and executes a program. State its advantages and disadvantages.
An interpreter is a language translator that processes a source program one statement or one small unit at a time. It translates a statement, executes it immediately, and then proceeds to the next statement.
Working process:
- The interpreter reads a source statement.
- It checks and translates the statement.
- If the statement is valid, it executes it.
- It repeats the process for subsequent statements.
- It normally stops and reports the error when an invalid statement is encountered.
Advantages:
- Errors can be detected and corrected interactively.
- It is useful for learning, testing, and rapid development.
- A separate executable file may not be necessary.
- Individual statements can often be tested immediately.
Disadvantages:
- Translation occurs during each execution, making the program slower.
- The interpreter and source code are generally required whenever the program runs.
- Distribution may be less convenient than distributing a standalone executable.
Python and JavaScript are commonly associated with interpreted execution, although modern implementations may combine interpretation with compilation.
Distinguish between a compiler and an interpreter.
A compiler and an interpreter both translate high-level language programs, but they differ in their methods.
| Basis | Compiler | Interpreter |
|---|---|---|
| Translation unit | Translates the complete program | Translates one statement or unit at a time |
| Execution | Program runs after compilation | Each statement is executed after translation |
| Error reporting | Usually reports errors after analyzing the program | Usually reports an error as soon as the faulty statement is reached |
| Execution speed | Compiled program generally runs faster | Execution is generally slower |
| Output | Commonly produces object code or an executable | Usually does not create a permanent standalone executable |
| Repeated runs | Existing executable can run without translating again | Source statements are normally translated again |
| Debugging | Edit-compile-run cycle may be required | Interactive testing is often easier |
| Examples | C and C++ implementations | Traditional Python and JavaScript implementations |
Conclusion: A compiler is generally preferred when execution speed and software distribution are important, whereas an interpreter is useful for interactive development, testing, and rapid feedback.
Define an assembler and describe the assembly process.
An assembler is system software that translates a program written in assembly language into machine or object code.
Assembly process:
- The programmer writes a source program using mnemonics, labels, registers, and symbolic operands.
- The assembler reads each assembly instruction.
- Mnemonics such as
ADDorMOVare converted into their corresponding machine operation codes. - Labels and symbolic addresses are entered into and resolved through a symbol table.
- The assembler checks for invalid instructions, undefined symbols, and incorrect operand formats.
- It generates object code and may also produce an error report or listing file.
- A linker may combine the object code with other modules and libraries to produce an executable program.
An assembler provides nearly a one-to-one mapping between assembly instructions and machine instructions, although directives and pseudo-instructions may not correspond directly to CPU instructions.
Differentiate among an assembler, compiler, and interpreter.
An assembler, compiler, and interpreter are translators, but they work with different source languages and use different translation methods.
| Translator | Input | Translation method | Typical output |
|---|---|---|---|
| Assembler | Assembly language | Converts mnemonics and symbolic addresses into machine instructions | Object or machine code |
| Compiler | High-level language | Translates the complete source program before execution | Object code or executable code |
| Interpreter | High-level language | Translates and executes statements progressively | Immediate execution, usually without a permanent executable |
Additional distinctions:
- An assembler generally has a close correspondence between source and machine instructions.
- A compiler performs more complex analysis because one high-level statement may generate several machine instructions.
- An interpreter combines translation and execution during program operation.
- Assembled and compiled programs generally execute faster than purely interpreted programs.
- Interpreters often provide quicker feedback during testing.
All three tools ultimately enable instructions written by programmers to be processed by computer hardware.
What is the program development cycle? List and briefly explain its major stages.
The program development cycle is a systematic sequence of activities used to understand a problem, design a solution, create a program, test it, and maintain it.
Major stages:
- Problem definition: Clearly identify the problem, objectives, inputs, outputs, and constraints.
- Problem analysis: Study requirements and determine the data, operations, resources, and special cases involved.
- Solution design: Develop algorithms, pseudocode, flowcharts, and suitable data structures.
- Coding: Convert the designed solution into a selected programming language.
- Translation: Use a compiler, interpreter, or assembler to process the source code.
- Testing and debugging: Execute the program with test data and remove detected errors.
- Documentation: Prepare technical and user documentation.
- Implementation: Install or deploy the program for actual use.
- Maintenance: Correct faults, improve performance, and adapt the program to new requirements.
The stages may be repeated because feedback from testing or maintenance can require changes to earlier decisions.
Explain the importance of problem definition and analysis in program development.
Problem definition and analysis form the foundation of successful program development. A programmer must understand what is required before attempting to write code.
Problem definition involves:
- Stating the problem clearly.
- Identifying the purpose and expected results.
- Determining the scope and limitations.
- Recognizing the intended users and operating environment.
Problem analysis involves:
- Identifying required inputs and their formats.
- Determining the processing operations.
- Specifying the required outputs.
- Studying constraints, assumptions, and exceptional cases.
- Dividing a complex problem into smaller subproblems.
- Evaluating possible solution approaches.
These stages prevent misunderstandings and reduce unnecessary coding. If requirements are incomplete or incorrect, even a technically correct program may solve the wrong problem. Careful analysis also supports accurate design, meaningful test cases, realistic planning, and easier maintenance.
Describe the role of algorithms, pseudocode, and flowcharts during program design.
Algorithms, pseudocode, and flowcharts are design tools used to plan a program before coding begins.
Algorithm:
- A finite, ordered set of unambiguous steps for solving a problem.
- It focuses on the logic of the solution rather than on a particular programming language.
- A good algorithm should be correct, definite, finite, and effective.
Pseudocode:
- A structured, informal description of an algorithm.
- It uses programming-like constructs such as
IF,WHILE, andFORwithout requiring strict language syntax. - It is easy to convert into source code.
Flowchart:
- A graphical representation of an algorithm.
- Standard symbols represent processing, input/output, decisions, and flow direction.
- It makes control flow and decision paths easier to visualize.
These tools help programmers detect logical mistakes early, communicate solutions to others, divide a problem into modules, and reduce coding time. Pseudocode is convenient for detailed logic, while flowcharts provide a visual overview.
Explain coding, testing, debugging, and documentation as stages of the program development cycle.
Coding:
- Coding converts the designed algorithm into source statements in a chosen programming language.
- Programmers should follow naming conventions, indentation rules, modular design, and suitable commenting practices.
Testing:
- Testing executes the program with selected data to determine whether it produces expected results.
- Test data should include normal values, boundary values, invalid values, and exceptional cases.
Debugging:
- Debugging is the process of locating, analyzing, and correcting errors discovered during translation or testing.
- It may involve tracing variables, examining outputs, using breakpoints, and retesting corrected code.
Documentation:
- Documentation records the program's purpose, design, code structure, installation process, and operating instructions.
- Internal documentation includes meaningful names and comments, while external documentation includes technical manuals and user guides.
Together, these stages turn a planned solution into a reliable and maintainable program.
Identify and explain the major types of programming errors encountered during program development.
The major types of programming errors are as follows:
1. Syntax errors:
- Violations of the grammatical rules of a programming language.
- Examples include a missing punctuation mark, an unmatched bracket, or a misspelled keyword.
- They are generally detected by a compiler or interpreter.
2. Semantic or type errors:
- Statements may follow the basic grammar but have an invalid meaning.
- Examples include applying an operation to incompatible data types or using an undeclared identifier.
- Many of these errors are detected during translation.
3. Runtime errors:
- Errors that occur while the program is executing.
- Examples include division by zero, invalid memory access, missing files, and unavailable resources.
4. Logical errors:
- The program runs but produces an incorrect result because the algorithm or expression is wrong.
- These errors are usually found through testing and careful examination of the program logic.
Correcting an error should always be followed by regression testing to ensure that the correction has not introduced new faults.
Explain the complete compilation and execution process of a high-level language program.
The compilation and execution process commonly includes the following stages:
- Source-code creation: The programmer writes and saves a source file using an editor or integrated development environment.
- Preprocessing: In languages that support it, preprocessor directives are handled, files may be included, and macros may be expanded.
- Compilation: The compiler checks the source program and translates it into assembly code or object code. Errors must be corrected before successful translation.
- Assembly: If assembly code is produced, an assembler converts it into object code.
- Linking: The linker combines object modules with required library routines. It resolves references between modules and creates an executable file.
- Loading: The operating system's loader places the executable and required libraries into main memory.
- Execution: The CPU begins executing instructions from the program's entry point.
- Runtime handling: The program receives input, processes data, produces output, and may use operating-system services.
- Termination: The program ends normally or stops because of a runtime error, returning control to the operating system.
A change to the source code normally requires the relevant compilation and linking stages to be repeated.
Distinguish among source code, object code, and executable code.
Source code:
- The original program written by a programmer in a high-level or assembly language.
- It is generally human-readable and can be edited.
- Examples include files containing C, C++, or assembly statements.
Object code:
- The machine-oriented code produced by a compiler or assembler for a source module.
- It may contain unresolved references to functions or data located in other modules or libraries.
- Therefore, it is not always ready to run independently.
Executable code:
- The final program produced after object files and required libraries have been linked.
- It contains the information needed by the operating system to load and start the program.
- It is generally ready for execution on a compatible system.
The usual relationship is:
Source code → Compiler or assembler → Object code → Linker → Executable code
Thus, source code is programmer-oriented, object code is an intermediate machine-level product, and executable code is the linked program prepared for loading and execution.
Explain the functions of the linker and loader in program execution.
The linker and loader prepare translated code for execution but perform different functions.
Functions of a linker:
- Combines one or more object files into a single program.
- Connects the program with required library routines.
- Resolves external symbols, such as a function defined in another module.
- Relocates addresses when necessary.
- Reports unresolved references or duplicate definitions.
- Produces an executable file or another linked object module.
Functions of a loader:
- Reads the executable file from secondary storage.
- Allocates memory for program code, data, stack, and other required areas.
- Loads the program and necessary shared libraries into memory.
- Performs final relocation or dynamic linking when required.
- Initializes the execution environment.
- Transfers control to the program's entry point.
In summary, the linker creates a complete executable from separate translated components, while the loader places that executable into memory and starts its execution.
Describe how a source program moves through editing, translation, linking, loading, and execution. Also indicate where errors may occur.
A program moves through several connected stages:
- Editing: The programmer creates or modifies source code. Typing mistakes and incorrect logic may be introduced at this stage.
- Translation: A compiler or assembler converts the source code into object code. Syntax, semantic, type, and symbol-related errors may be reported.
- Linking: The linker combines object files and libraries. Undefined functions, missing libraries, or duplicate definitions can cause linker errors.
- Loading: The loader places the executable in memory and prepares its runtime environment. Loading can fail because of insufficient memory, incompatible formats, or missing shared libraries.
- Execution: The CPU runs the loaded instructions. Runtime errors may occur because of invalid input, unavailable resources, illegal memory access, or division by zero.
- Result verification: The programmer compares actual output with expected output. Incorrect results may reveal logical errors even when all earlier stages succeeded.
When an error is found, the programmer usually returns to the editing stage, corrects the source code, and repeats the necessary stages. This repeated sequence is often called the edit-translate-link-run cycle.
Discuss the factors that influence the choice between machine language, assembly language, and a high-level language for solving a problem.
The choice of programming language level depends on the requirements of the application.
Important factors include:
- Hardware control: Machine or assembly language may be preferred when direct access to registers, instructions, or devices is required.
- Execution efficiency: Low-level code can provide precise performance control, although modern optimizing compilers can also produce highly efficient code.
- Development time: High-level languages reduce the amount of code and usually support faster development.
- Portability: High-level languages are preferable when software must run on different processors or operating systems.
- Readability and maintenance: High-level source code is normally easier to understand, debug, and modify.
- Memory limitations: Embedded systems with strict resource limits may require assembly for selected operations.
- Available translators and tools: The target system must support a suitable assembler, compiler, interpreter, debugger, and libraries.
- Programmer expertise: Low-level programming requires detailed knowledge of processor architecture.
- Application type: Device drivers and firmware may use low-level code, while business, scientific, and web applications generally use high-level languages.
In practice, systems often combine languages: most of the program is written in a high-level language, while small performance-critical or hardware-specific sections use assembly language.
Define machine language. Explain its main characteristics, advantages, and limitations.
Machine language is the lowest-level programming language understood and executed directly by a computer's processor. Its instructions are represented using binary digits, namely 0 and 1.
Main characteristics:
- Instructions are written in binary form.
- Each instruction usually contains an operation code and one or more operand addresses.
- It is specific to a particular processor architecture.
- It does not require a translator before execution.
Advantages:
- It is executed directly by the CPU.
- Programs can run very quickly.
- It provides direct control over hardware resources.
Limitations:
- Binary instructions are difficult to read, write, and remember.
- Programming and debugging are time-consuming.
- Errors are common and difficult to locate.
- A program written for one processor may not work on another processor.
Thus, machine language provides maximum hardware control but has poor readability, portability, and ease of development.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →