- Goals of Assemblers
- Source
- Object
- Info for Loaders
- Usually: Line at a time processing
- OK except for FORWARD REFERENCE problem
- The Two Pass assembler
- Data Structures
- Location Counter
- Symbol Table
Label (name), Value (addr), other attributes
- Pass 1
- Establish Addresses
- Create Symbol Table
- Pass 2
- (read it again)
- Generate Code
- Example: "Simple Machine"
Single Accumulator (need not reference it)
Instructions OP : CODE
HALT 00 LOAD 11 STORE 12 CMP 31
ADD 21 SUB 22 MUL 23 DIV 24
JMP 41 JE 42 JNE 43 JG 44
JL 45 JLE 46 JGE 47 JNE 48
CALL 51 RET 53
Program:
loc op address
BEGIN LOAD X
ADD Y
ADD Z
STORE ANS
HALT
Z DW 24
Y DW -4
X DW 7
ANS DW ?
END BEGIN
- Pseudo Ops (assembler instructions)
DW Memory allocation and initialize
END End of program and Start Address
EQU Load Symbol Table
ORG Set Loc Ctr
* Reference Location Counter
- Another Example
loc op address
ORG 100
DELTA EQU 3
BEGIN LOAD X
ADDI 5
ADD Y
SUBI DELTA
ADD Z
STORE ANS
HALT
ORG 200
Z DW 24
Y DW -4
ANS ORG * + 1
X DW 7
END BEGIN
- Forward Reference Problem
- More on symbol table
- associative memory
- binary search
- hash coding
- other entries
- length (type on Pentium)
- segment
- (info for loader)
- Macros
- Open subroutine
- Purpose: Make life easier
(really: text processing)
- Structure
Header name macro p1, p2, ...
Model statements lll ooo aaa
End endm
- Simple examples (no params)
- Subroutine similarity
- Parameters
- Duplicate label problem
local l1, l2, ...