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

Assembler: Translating Assembly Language

This document discusses different types of translators including compilers, interpreters, and assemblers. It provides examples of each and compares their advantages and disadvantages. Specifically, it notes that compilers convert an entire program at once, interpreters convert code line-by-line, and assemblers translate assembly language to machine code. The document also provides an example of using an assembler and compiler to output "Hello World" in assembly language on Windows.

Uploaded by

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

Assembler: Translating Assembly Language

This document discusses different types of translators including compilers, interpreters, and assemblers. It provides examples of each and compares their advantages and disadvantages. Specifically, it notes that compilers convert an entire program at once, interpreters convert code line-by-line, and assemblers translate assembly language to machine code. The document also provides an example of using an assembler and compiler to output "Hello World" in assembly language on Windows.

Uploaded by

Musa Jubril
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

CSC 218 Foundation of Sequential Program


Lecture Note 3
(Assemblers Specification and Translation of P/L)

Translators

A translator is a programming language processor that converts a computer


program from one language to another. It takes a program written in source code
and converts it into machine code. It discovers and identifies the error during
translation.

Purpose of Translator
It translates high-level language program into a machine language program
that the central processing unit (CPU) can understand. It also detects errors in the
program.

Different Types of Translators


There are 3 different types of translators as follows:

Compiler
A compiler is a translator used to convert high-level programming language to
low-level programming language. It converts the whole program in one session
and reports errors detected after the conversion. Compiler takes time to do its
work as it translates high-level code to lower-level code all at once and then saves
it to memory. A compiler is processor-dependent and platform-dependent. But it
has been addressed by a special compiler, a cross-compiler and a source-to-source
compiler. Before choosing a compiler, user has to identify first the Instruction Set
Architecture (ISA), the operating system (OS) and the programming language that
will be used to ensure that it will be compatible.

1
2

Fig.: Compiler
Interpreter
Just like a compiler, is a translator used to convert high-level programming
language to low-level programming language. It converts the program one at a
time and reports errors detected at once, while doing the conversion. With this, it
is easier to detect errors than in a compiler. An interpreter is faster than a
compiler as it immediately executes the code upon reading the code.
It is often used as a debugging tool for software development as it can execute a
single line of code at a time. An interpreter is also more portable than a compiler
as it is not processor-dependent, you can work between hardware architectures.

Fig.: Interpreter

Assembler
An assembler is is a translator used to translate assembly language to machine
language. It is like a compiler for the assembly language but interactive like an
interpreter. Assembly language is difficult to understand as it is a low-level
programming language. An assembler translates a low-level language, an
assembly language to an even lower-level language, which is the machine code.
The machine code can be directly understood by the CPU.

Fig.: Assembler

2
3

Examples of Translators
Here are some examples of translators per type:

Advantages and Disadvantages of Translators


Here are some advantages of the Compiler:
• The whole program is validated so there are no system errors.
• The executable file is enhanced by the compiler, so it runs faster.
• User do not have to run the program on the same machine it was created.

Here are some disadvantages of the Compiler:


• It is slow to execute as you have to finish the whole program.
• It is not easy to debug as errors are shown at the end of the execution.
• Hardware specific, it works on specific machine language and architecture.

Here are some advantages of the Interpreter:


• You discover errors before you complete the program, so you learn from
your mistakes.
• Program can be run before it is completed so you get partial results
immediately.

3
4

• You can work on small parts of the program and link them later into a
whole program.

Here are some disadvantages of the Interpreter:


• There’s a possibility of syntax errors on unverified scripts.
• Program is not enhanced and may encounter data errors.
• It may be slow because of the interpretation in every execution.

Here are some advantages of the Assembler:


• The symbolic programming is easier to understand thus time-saving for the
programmer.
• It is easier to fix errors and alter program instructions.
• Efficiency in execution just like machine level language.

Here are some disadvantages of the Assembler:


• It is machine dependent, cannot be used in other architecture.
• A small change in design can invalidate the whole program.
• It is difficult to maintain.

INTRODUCTION TO ASSEMBLY LANGUAGE


Assembly Language is a low-level programming language. It helps in understanding
the programming language to machine code. In computers, there is an assembler that
helps in converting the assembly code into machine code executable. Assembly
language is designed to understand the instruction and provide to machine language for
further processing. It mainly depends on the architecture of the system whether it is the
operating system or computer architecture.
Assembly Language mainly consists of mnemonic processor instructions or data, and
other statements or instructions. It is produced with the help of compiling the high-level
language source code like C, C++. Assembly Language helps in fine-tuning the
program.

Why is Assembly Language Useful?


Assembly language helps programmers to write human-readable code that is
almost similar to machine language. Machine language is difficult to understand
and read as it is just a series of numbers. Assembly language helps in providing

4
5

full control of what tasks a computer is performing.

Example:
Find the below steps to print “Hello world” in Windows
1. Open the notepad.
2. Write below code
global _main
extern _printf
section .text
_main:
push message
call _printf
add esp, 4
ret
message:
db 'Hello, World!', 10, 0
3. Save the file with any name example [Link], the extension should be
“.asm”.
4. The above file needs to compile with the help of an assembler that is
NASM (Netwide Assembler).
5. Run the command nasm –f win32 [Link]
6. After this, Nasm creates one object file that contains machine code but not
the executable code that is [Link]
7. To create the executable file for windows Minimal GNU is used that
provides the GCC compiler.
8. Run the command gcc –o [Link] [Link]

5
6

9. Execute the executable file now “XYZ”


10. It will show the output as “Hello, world”.

Why You Should Learn Assembly Language?


The learning of assembly language is still important for programmers. It helps in
taking complete control over the system and its resources. By learning assembly
language, the programmer is able to write the code to access registers and able to
retrieve the memory address of pointers and values. It mainly helps in speed
optimization that increases efficiency and performance.
Assembly language learning helps in understanding the processor and memory
functions. If the programmer is writing any program that needs to be a compiler
that means the programmer should have a complete understanding of the
processor. Assembly language helps in understanding the work of processors and
memory. It is cryptic and symbolic language.

Why you should learn Assembly Language?


The learning of assembly language is still important for programmers. It helps in
taking complete control over the system and its resources. By learning assembly
language, the programmer is able to write the code to access registers and able to
retrieve the memory address of pointers and values. It mainly helps in speed
optimization that increases efficiency and performance.
Assembly language learning helps in understanding the processor and memory
functions. If the programmer is writing any program that needs to be a compiler
that means the programmer should have a complete understanding of the
processor. Assembly language helps in understanding the work of processors and
memory. It is cryptic and symbolic language.

6
7

Assembly Language helps in contacting the hardware directly. This language is


mainly based on computer architecture and it recognizes the certain type of
processor and its different for different CPUs. Assembly language refers as
transparent compared to other high-level languages. It has a small number of
operations but it is helpful in understanding the algorithms and other flow of
controls. It makes the code less complex and easy debugging as well.

Features
The features of the assembly language are mentioned below:
1. It can use mnemonic than numeric operation code and it also provides the
information of any error in the code.
2. This language helps in specifying the symbolic operand that means it does
not need to specify the machine address of that operand. It can be
represented in the form of a symbol.
3. The data can be declared by using decimal notation.

Assemblers
The assemblers are used to translate the assembly language into machine
language. There are two types of assembler are:
1. Single-pass assembler: A single assembler pass is referred as the complete
scan of source program input to assembler or equivalent representation and
translation by the statement on the basis of statement called as single pass
assembler or one pass translation. It isolates the label, mnemonics and
operand field of the system. It validates the code instructions by looking it
up in mnemonic code table. It enters the symbol found in the label field and
the address of the text available machine word into the symbol table. This
pass is fast and effected, and no need to construct the intermediate code.
2. Multi-pass assembler: In this, an assembler goes through assembly
language several times and generates the object code. In this last pass is

7
8

called a synthesis pass and this assembler requires any form of an


intermediate code to generate each pass every time. It is comparatively
slower than single pass assembler but there can be some actions that can be
performed more than once means duplicated.

Advantages and Disadvantages


Mentioned are some advantages and disadvantages:

Advantages
Below are the advantages:
1. It allows complex jobs to run in a simpler way.
2. It is memory efficient, as it requires less memory.
3. It is faster in speed, as its execution time is less.
4. It is mainly hardware oriented.
5. It requires less instruction to get the result.
6. It is used for critical jobs.
7. It is not required to keep track of memory locations.
8. It is a low-level embedded system.

Disadvantages
Below mentioned are the disadvantages:
1. It takes a lot of time and effort to write the code for the same.
2. It is very complex and difficult to understand.
3. The syntax is difficult to remember.
4. It has a lack of portability of program between different computer
architectures.
5. It needs more size or memory of the computer to run the long programs
written in Assembly Language.

Common questions

Powered by AI

Compilers, interpreters, and assemblers all serve as translators, but they differ in process and application. A compiler translates high-level programming languages into machine code all at once, which means it validates the entire program before execution, leading to faster executable files. However, it is platform-dependent and slow to execute because errors are identified only after compilation . An interpreter translates high-level code into machine code line-by-line, allowing immediate error detection and execution, making it ideal for debugging. It is portable across platforms but slower because it interprets code at runtime . An assembler converts assembly language, a low-level language, directly to machine code. It enables closer control over hardware but is machine-dependent and not portable. Maintanance is complex due to its dependency on specific system architecture .

Assemblers help understand computer architecture by translating assembly language, which is closely tied to the system's processor instructions, directly into machine code the CPU can execute. This translation process necessitates an understanding of how the processor accesses memory and processes instructions, making assembly language a reflection of the computer architecture itself. It enables programmers to write code that manipulates hardware directly, offering insight into the machinery's inner workings, unlike high-level languages that abstract these details .

Assemblers translate assembly language directly to machine code, resulting in efficient program execution similar to machine-level language. This process is streamlined because assemblers do not involve the additional steps required to translate high-level languages. Unlike compilers for high-level languages, which optimize code after translation, assemblers directly map human-understandable mnemonics to machine instructions, reducing computational overhead and enhancing runtime performance .

Despite its advantages in performance and control, assembly language poses significant challenges. Its syntax is complex and cryptic, making it difficult to write and debug. Its non-portability across different architectures increases maintenance overhead since a small design change may necessitate significant code restructuring. Additionally, writing efficient assembly code demands intricate understanding of the specific hardware, which may require considerable time and skill .

Learning assembly language is beneficial for gaining detailed control over hardware resources and enhancing performance through speed optimization. It allows programmers to access system functions like registers and memory addresses directly, offering insight into processor and memory workings. This understanding aids tasks like writing compilers that require knowledge of processor operations. Assembly language provides transparency between the high-level code and machine code, enabling precise manipulation of hardware .

A compiler processes the entire program as a whole, translating it to machine code before execution. This means all errors are reported only after the entire program is parsed, potentially making debugging more cumbersome. Conversely, an interpreter translates code line-by-line, immediately executing each statement. This allows for immediate error detection and handling, which is beneficial during development for frequent debugging but results in slower overall execution speeds due to real-time code interpretation .

A single-pass assembler is preferred when execution speed is critical and intermediate storage of symbol tables or intermediate code is unnecessary. It scans the source program only once, making it faster but limiting its ability to handle complex dependencies. Therefore, it's ideal for simpler assembly tasks without forward references . Conversely, a multi-pass assembler is suitable for more complex code with forward references, where the assembler needs to construct a symbol table and perform comprehensive checks. It is slower because it processes the source code multiple times, but it supports more complex instruction sets and optimizations .

Assemblers contribute to memory efficiency by converting low-level assembly language directly to machine code without the need for additional abstraction layers or optimization codes required by high-level languages. This direct translation results in smaller executable files, as it eliminates extraneous run-time environment components. Assembly language's closeness to machine code allows precise control over memory usage and instruction execution, optimizing hardware efficiency .

Symbolic operands in assembly language make code easier to read and write by allowing programmers to use human-friendly labels instead of numeric memory addresses. This simplifies maintenance and debugging by abstracting complex memory management details. However, reliance on symbolic names requires precise symbol table management by assemblers, which may complicate code in large applications. While it aids human comprehension, it can introduce overhead during the translation process as labels are resolved to actual memory addresses .

Understanding the Instruction Set Architecture (ISA) is crucial when selecting a compiler because the compiler generates machine code that is executed directly by the CPU. Different ISAs support specific machine instructions, so the compiler must be compatible with the target CPU architecture to ensure correct program execution. Selection without considering ISA may lead to incompatible code that does not function correctly on the intended processor .

You might also like