1.2 Assembler Notes
1.2 Assembler Notes
1.2 Assembler Notes
Assemblers
for CISC Machines: case study x85 & x86 machines.
1|Page
Terminologies:
2. Literals: Constant value. Example: R1=a+8, 8 is literal. Literals are stored in literal table
data structure.
3. Symbols/labels: Symbols or labels are just like variables in any other language. Example
int a=5; Symbol table is used to handle such things
4. Mnemonics: A small word that acts as an identifier for the instruction. The mnemonics
are written in code segment. In following examples mov, sub, add, jmp, call, and mul are
the mnemonics:
Since mnemonics replace machine instruction it is easy to write, debug and understand in
comparison to machine codes.
Useful to write lightweight application (in embedded system like traffic light) because it
needs fewer codes than high level language.
Mnemonics in assembly language are in abbreviated form and in large number, so they
are hard to remember.
Program written in assembly language are machine dependent, so are incompatible for
different type of machines.
2|Page
A program written in assembly language is less efficient to same program in machine
language.
This table consists of the fields: Name of mnemonic, binary value, instruction length,
format of instruction.
MOT table is used to look up mnemonic operation codes and translate them to their
machine language equivalents.
Example:
3|Page
Pseudo Actions
START It is used to specify the starting execution
of a program.
USING It specifies the base table register that is
been used.
DROP It is used to remove the register used in
the base table.
3. Symbol Table
Symbol table is used for keeping the track of symbol that are defined in the program.
It is used to give a location for a symbol specified.
The assembler creates the symbol table section for the object file. It makes an entry in the
symbol table for each symbol that is defined or referenced in the input file and is needed
during linking
• In pass 1, whenever a symbol is defined corresponding entry is made in symbol table.
• In pass2, symbol table is used for generating machine code of a symbol.
4. Literal Table
Value of literal Length of literal
28 4 byte
15 4 byte
Literal table is used for keeping track of literals that are encountered in the programs.
• We directly specify the value, literal is used to give a location for the value.
• In pass 1, whenever a Literal is defined and for entry is made in Literal table.
• In pass2, Literal table is used for generating binary code of a Literal.
Literals are always encountered in the operand field of an instruction.
4|Page
5. Base Table
This store the information of available register in hardware of the system. Example,
Register1 is free but R2 and R3 are not free.
Register Available
R1 Free
R2 Not Free
R3 Not Free
a) One-pass assembler:
Purpose:
One pass assembler converts assembly code into machine language just using single scan.
Remember literals
One pass assembler is the assembler which assigns the memory addresses to the variables (i.e.
label definitions) and translates the source code into machine code (i.e. assembly) in the first
pass simultaneously.
A one pass assembler passes over the source file exactly once, in the same pass collecting the
labels, resolving future references and doing the actual assembly. The difficult part is to resolve
future label references (the problem of forward referencing) and assemble code in one pass. The
one pass assembler prepares an intermediate file, which is used as input by the two pass
assembler.
5|Page
Forward Reference Problem in Pass-1 Assembler:
R2=? Forward Reference problem means R2 not available now. So, Pass1- assembler gives error.
To avoid this issue solution is Two pass assembler. In Pass2 assembler first complete code is
analyzed and all values will be stored in table.
In
R1=3,
MUL R1, R2
A = B+28
MUL = 1101001
R1 = 0011
R2 = ? (R2 not available here)
……..
R1 DC ‘2’ (Decrement value of R1 by 2)
R2 = 10, DC ‘7’ (Decrement value of R2 by 7)
6|Page
7|Page
ALGORITHM STEPS FOR PASS 1 ASSEMBLER
Step2. Read assembly language program and separate all the symbols into symbol table. Now,
verify whether opcode is Machine opcode or Pseudo opcode
Step3: If Pseudo opcode, search POT: and check the type of Pseudo opcode.
Step4: If machine opcode,: i.e obtain information about binary code, format and length of
instruction.
Step8: Now free the register used by DROP command during the operation.
Step9: Finally forward all tables to Pass 2 for converting into machine code.
b) Two-pass-assembler:
A Two Pass Assembler is the assembler which reads the source code twice. In the first pass, it
reads all the variables and assigns them memory addresses. In the second pass, it reads the source
code and translates the code into object code.
OR
A two pass assembler does two passes over the source file (the second pass can be over an
intermediate file generated in the first pass of the assembler). In the first pass all it does is looks
for label definitions and introduces them in the symbol table (a dynamic table which includes the
label name and address for each label in the source program). In the second pass, after the
8|Page
symbol table is complete, it does the actual assembly by translating the operations into machine
codes and so on.
Note: In First phase complete code is analyzed and all variables with their values are
assigned in table. Pass2 now along with table code is translated into binary format. So, no
chances of any error because already we have find out all values in the table first.
9|Page
DC: Declare constant, formed binary of constant values.
10 | P a g e
11 | P a g e
TWO PASS ASSEMBLER ALGORITHM STEPS
In first pass itself complete assembly For same operation it performs two passes.
program is converted into machine code i.e., First pass it collects the collects the symbols
it collects the symbols or labels, pseudo or labels, pseudo keyword, operators, literals
keyword, operators, literals in their in their respective table data structure. Now
respective table data structure. After this i.e run Second pass and converts everything into
within same pass immediately fetch the binary format.
stored information from table and converts
into machine code. Both of these processes
could be done together.
All entries for symbols (i.e variable) and Literals are stored in literal table and
12 | P a g e
literals (i.e constants like 18) are entered into symbols are stored in symbol table.
symbol table only.
Suffers from forward reference problem It does not have forward reference problem
2. The 8085 is a conventional von Neumann design based on the Intel 8080.
2. It is a 16-bit Microprocessor having 20 address lines and16 data lines that provides up to
1MB storage
13 | P a g e
3. It supports two modes of operation, i.e. Maximum mode and Minimum mode. Maximum
mode is suitable for system having multiple processors and Minimum mode is suitable
for system having a single processor.
4. x86 assembly languages are used to produce object code for the x86 class of processors
5. Like all assembly languages, it uses short mnemonics to represent the fundamental
instructions that the CPU in a computer can understand and follow.
6. The x86 architecture has:
8085 is a 8 bit processor, number of flags are 8086 is a 16 bit processor, number of flags
5 and memory capacity is 64KB are 9 and memory capacity is 1 MB
14 | P a g e
Table1: Assembly Language Instructions for X85 and X86
OR of byte or word
CMP- Compare
15 | P a g e
IRET- Enable Disable Ex1. EI if cpu Ex1. IRET if cpu
Processor EI-Enable Interrupt
Interrupt utilization>90% utilization >90%
Control DI-Disable Interrupt ESC-Escape to external
processor interface
Instructions NOP- No operation
LOCK-Lock bus during
next instruction
HLT-Halt processor
NOP-No operation
HLT-Halt processor
16 | P a g e