0% found this document useful (0 votes)
17 views2 pages

Exercises

The document outlines the differences between compilers and interpreters, highlighting that compilers translate entire source code into machine code before execution, while interpreters execute code line-by-line at runtime. It discusses the advantages of each, such as performance and error detection for compilers, and immediate execution and portability for interpreters. Additionally, it covers the benefits of compiling to assembly language, using C as a target language, and the key tasks performed by assemblers.

Uploaded by

Teshome Girma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Exercises

The document outlines the differences between compilers and interpreters, highlighting that compilers translate entire source code into machine code before execution, while interpreters execute code line-by-line at runtime. It discusses the advantages of each, such as performance and error detection for compilers, and immediate execution and portability for interpreters. Additionally, it covers the benefits of compiling to assembly language, using C as a target language, and the key tasks performed by assemblers.

Uploaded by

Teshome Girma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercises

• What is the difference between a compiler and an


interpreter?

• What are the advantages of (a) a compiler over an interpreter

(b) an interpreter over a compiler?

• What advantages are there to a language-processing system in which the compiler produces
assembly language rather than machine language?

• A compiler that translates a high-level language into another high-level language is called a
source-to-source translator. What advantages are there to using C as a target language for a
compiler?

• Describe some of the tasks that an assembler needs to perform.

1. Difference Between a Compiler and an Interpreter


 Compiler: Translates the entire source code of a program into machine code (or
another high-level language) before execution. This results in a standalone
executable file.
 Interpreter: Translates and executes source code line-by-line or statement-by-
statement at runtime without producing a separate executable file.

2. Advantages

(a) Advantages of a Compiler over an Interpreter:

 Performance: Compiled code runs faster because it is translated into machine


code before execution.
 Optimization: Compilers can optimize the entire codebase, improving runtime
performance.
 Error Detection: Errors are caught during the compilation phase, making
debugging easier.
 Distribution: Compiled programs are easier to distribute since they don't
require the source code or a compiler to run.

(b) Advantages of an Interpreter over a Compiler:

 Immediate Execution: Interpreters allow for immediate execution of code,


which is beneficial during development and testing.
 Portability: Interpreted languages can run on any machine with the appropriate
interpreter, improving cross-platform compatibility.
 Ease of Use: Developers can modify code and see results instantly, facilitating
rapid prototyping.
3. Advantages of Compiling to Assembly Language
 Portability: Assembly code can be adapted for different target architectures
more easily than machine code.
 Debugging: Assembly language provides a more human-readable format than
machine code, making debugging straightforward.
 Optimization: It allows for more advanced optimizations tailored to specific
hardware architectures before converting to machine code.

4. Advantages of C as a Target Language for a


Compiler
 Performance: C is close to machine code, enabling efficient execution and
optimizations.
 Rich Features: C supports low-level operations while also providing higher-level
abstractions, making it versatile for various applications.
 Widespread Use: C is widely used and supported, making it easier to find
references and tools related to it.
 Portability: Code written in C can often be compiled on different platforms with
minimal changes.

5. Tasks of an Assembler
An assembler performs several key tasks, including:

 Symbol Resolution: Converts symbolic addresses (like labels) into actual


memory addresses.
 Translation: Converts assembly language instructions into machine code.
 Handling Directives: Processes assembler directives for data allocation, macro
definitions, and segment definitions.
 Relocation: Adjusts addresses in the generated code based on where the code
will be loaded in memory.
 Generating Output: Produces an object file or executable file, which may be
used by linkers.

You might also like