0% found this document useful (0 votes)
47 views32 pages

CA0216D Chapter3

Chapter 3 discusses the assembly and execution process of programs, detailing how assembly language is translated into binary machine language for execution. It explains the roles of assemblers, linkers, and loaders in this process, as well as the data structures used, such as symbol and opcode tables. The chapter also covers the syntax of assembly language and provides examples of assembly instructions and their functions.

Uploaded by

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

CA0216D Chapter3

Chapter 3 discusses the assembly and execution process of programs, detailing how assembly language is translated into binary machine language for execution. It explains the roles of assemblers, linkers, and loaders in this process, as well as the data structures used, such as symbol and opcode tables. The chapter also covers the syntax of assembly language and provides examples of assembly instructions and their functions.

Uploaded by

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

CHAPTER 3

ASSEMBLY AND EXECUTION OF PROGRAMS


Chapter3 Objectives
• Assembly and execution of programs
• Assembly and execution process
• Assemblers
• Data Structures
• Pass one in a two-pass assembler
• Pass two in a two-pass assembler
Assembly and Execution of programs
• A program written in assembly language needs to be translated into
binary machine language before it can be executed.
• In this section, we will learn how to get from the point of writing an
assembly program to the execution phase.
• Figure 3.3 shows steps in the assembly and execution process.
Assembly and Execution process
Assembly and Execution of programs
• The assembler reads the source program in
assembly language and generates the object
program in binary form.
• The object program is passed to the linker.
• The linker will check the object file for calls to
procedures in the link library.
• The linker will combine the required procedures
from the link library with the object program
and produce the executable program.
• The loader loads the executable program into
memory and branches the CPU to the starting
address.
• The program begins execution.
3.4.1. Assemblers
• Assemblers are programs that generate machine code instructions
from a source code program written in assembly language.
• The assembler will replace symbolic addresses by numeric addresses,
replace symbolic operation codes by machine operation codes,
reserve storage for instructions and data, and translate constants into
machine representation.
• The functions of the assembler can be performed by scanning the
assembly program and mapping its instructions to their machine code
equivalent
3.4.1 Assemblers and Assembly
Language
• Compare the machine code to the assembly code
• You will find the assembly code much easier to decipher
• Mnemonics instead of op codes
• Variable names instead of memory locations
• Labels (for branches) instead of memory locations
• Assembly Language is an intermediate language (low-level Programming language)
between the instruction set (machine language) and the high-level language> it is
designed for a specific type of processor.
• The assembler is a program that takes an assembly language program (assembly
codes) and assembles it into machine language (machine codes), much like the
compiler compiles a high-level language program (i.e converts source code directly
to machine code
• Today we have very sophisticated compilers that provide highly optimized code, so
there is no need to ever program in assembly language
3.4.1 Assemblers and Assembly Language
While assembly languages differ between processor architectures, they often
include similar instructions and operators. Below are some examples of instructions
supported by x86 processors.
 MOV - move data from one location to another
 ADD - add two values
 SUB - subtract a value from another value
 PUSH - push data onto a stack
 POP - pop data from a stack
 JMP - jump to another location
 INT - interrupt a process
3.4.2. Data Structures
• The assembler uses at least three tables
to perform its functions: symbol table,
opcode table, and pseudo instruction Pass one in a two-pass assembler
table.
• The symbol table, which is generated in
pass one, has an entry for every symbol
in the program
• Associated with each symbol are its
binary value and other information.
Symbol Table
Opcode Table

• The opcode table provides information about


the operation codes
Pass two in a two-pass assembler
• Associated with each symbolic opcode in the
table are its numerical value and other
information about its type, its instruction
length, and its operands
Pseudo instruction table
• The entries of the pseudo instruction table are the pseudo instructions symbols. Most
commonly used are LDR and ADR.
• The LDR allows a 32-bit immediate data to be loaded into a register while the ADR will
load a program counter (PC)- relative address into a register (usually using ADD) without
updating APSR. Also, both LDR and ADR pseudo-instructions can be used to set registers
to a program address valve.
• Each entry refers the assembler to a procedure that processes the pseudo instruction
when encountered in the program.
• For example, if END is encountered, the translation process is terminated.
ILC (Instruction Location
Counter)
• In order to keep track of the instruction locations, the assembler
maintains a variable called instruction location counter (ILC).
• The ILC contains the value of memory location assigned to the
instruction or operand being processed.
ILC (Instruction Location
Counter)
• The ILC is initialized to 0 and is incremented after processing each
instruction.
• The ILC is incremented by the length of the instruction being
processed, or the number of bytes allocated as a result of a data
allocation pseudo instruction.
• Figures 3.4 and 3.5 show simplified flowcharts of pass one and pass
two in a two pass assembler.
• The main function of pass one is to build the symbol table while pass
two’s main function is to generate the object code
3.4.3. Linker and Loader
• The linker is the entity that can combine object modules that may
have resulted from assembling multiple assembly modules separately
• The loader is the operating system utility that reads the executable
into memory and start execution.
• In summary, after assembly modules are translated into object
modules, the functions of the linker and loader prepare the program
for execution.
• These functions include combining object modules together, resolving
addresses unknown at assembly time, allocating storage, and finally
executing the program.
REGISTER ADDRESSING
 Instruction gets its source data from a register
 Data resulting from an operation is stored in another register.
 Data length depends on register being used:
- 8-bit registers: AH, AL, BH, BL, CH, CL, DH, DL.
- 16-bit registers: AX, BX, CX, DX, SP, BP, SI, DI.
- 32-Bit registers: EAX, EBX, ECX, EDX, ESP, EBP, ESI, EDI.
- 64-bit registers: RAX, RBX, RCX, RDX, RSP, RBP, RSI, RDI and R8 through R15
Example:
•The following assembly language can be used to add the numbers 3 and 4:
mov eax, 3 - loads 3 into the register "eax"
mov ebx, 4 - loads 4 into the register "ebx"
add eax, ebx, ecx - adds "eax" and "ebx" and stores the result (7) in "ecx"
Syntax of assembly language
Assembly language statements are entered one statement per line. Each statement follows
the following format −

[label] mnemonic [operands] [;comment]

The fields in the square brackets are optional. A basic instruction has two parts, the first one
is the name of the instruction (or the mnemonic), which is to be executed, and the second
are the operands or the parameters of the command.
INC COUNT ; Increment the memory variable COUNT
MOV TOTAL, 48 ; Transfer the value 48 in the ; memory variable TOTAL
ADD AH, BH ; Add the content of the ; BH register into the AH register
AND MASK1, 128 ; Perform AND operation on the ; variable MASK1 and 128
ADD MARKS, 10 ; Add 10 to the variable MARKS
MOV AL, 10 ; Transfer the value 10 to the AL register
Syntax of assembly language

A typical assembly language consists of 3 types of instruction statements that are used to define program
operations: Mnemomics, [operand] [; comment/description]
 Opcode mnemonics: This is the actual to run. Some operations take one parameter. Some take multiple.
 Data definitions.
 Assembly directives.

 Comments in Assembly are anything that comes after a semicolon (;)


End of Slides!!
•Here is an example of assembly language. The below code signals to a processor in binary code
to add the numbers 3 and 4:
•1: MOV eax, 3
MOV ebx, 4
ADD eax, ebx, ecx
•In this example, "1:" is the label, which lets the computer know where to begin the operation.
The "MOV" and "ADD" is the mnemonic command to move the number 3 into a part of the
computer processor where it can function as a variable. "EAX," "EBX" and "ECX" are the
variables. The first line of code loads 3 into the register "eax." The second line of code loads 4
into the register "ebx." The last line of code adds "eax" and "ebx" and stores the result of the
addition, which is seven, in "ecx."
•Some professional industries still use this kind of code. For example, some financial firms and
marketplaces use high-frequency trading (HFT) platforms that are written in assembly language.
By only having the processor translate from an assembly code, they save processing time that
other firms may spend on the additional translation from a higher-level code.
Writing values
Example

You might also like