One Pass Multi Pass Assembler and Implementation Examples
One Pass Multi Pass Assembler and Implementation Examples
One-pass assemblers
Multi-pass assemblers
Two-pass assembler with overlay structure
1
Two-Pass Assembler with Overlay
Structure
2
One-Pass Assemblers
Main problem
» forward references
– data items
– labels on instructions
Solution
» data items: require all such areas be defined before they are
referenced
» labels on instructions: no good solution
3
One-Pass Assemblers
Main Problem
» forward reference
– data items
– labels on instructions
Two types of one-pass assembler
» load-and-go
– produces object code directly in memory for immediate
execution
» the other
– produces usual kind of object code for later execution
4
Load-and-go Assembler
Characteristics
» Useful for program development and testing
» Avoids the overhead of writing the object program out and
reading it back
» Both one-pass and two-pass assemblers can be designed
as load-and-go.
» However one-pass also avoids the over head of an
additional pass over the source program
» For a load-and-go assembler, the actual address must be
known at assembly time, we can use an absolute program
5
Forward Reference in One-pass Assembler
6
Load-and-go Assembler (Cont.)
7
Producing Object Code
8
Multi-Pass Assemblers
9
Implementation Examples
10
Microsoft MASM Assembler
SEGMENT
» a collection segments, each segment is defined as
belonging to a particular class, CODE, DATA, CONST,
STACK
» registers: CS (code), SS (stack), DS (data), ES, FS, GS
» similar to program blocks in SIC
ASSUME
» e.g. ASSUME ES:DATASEG2
» e.g. MOVE AX, DATASEG2
MOVE ES,AX
» similar to BASE in SIC
11
Microsoft MASM Assembler
12
Sun Sparc Assembler
Sections
» .TEXT, .DATA, .RODATA, .BSS
Symbols
» global vs. weak
» similar to the combination of EXTDEF and EXTREF in SIC
Delayed branches
» delayed slots
» annulled branch instruction
13
Sun Sparc Assembler
LOOP: . LOOP: .
.
ADD %L2, %L3, %L4 .
CMP %L0, 10 .
BLE LOOP
. ADD %L2, %L3, %L4
CMP %L0, 10
BLE LOOP
. NOP
.
CMP %L0, 10
BLE LOOP
ADD %L2, %L3, %L4
.
14
Sun Sparc Assembler
15
AIX Assembler for PowerPC
Similar to System/370
Base relative addressing
» save instruction space, no absolute address
» base register table:
– general purpose registers can be used as base register
» easy for program relocation
– only data whose values are to be actual address needs to be
modified
» e.g. USING LENGTH, 1
» USING BUFFER, 4
» Similar to BASE in SIC
» DROP
16
AIX Assembler for PowerPC
Alignment
» instruction (2)
» data: halfword operand (2), fullword operand (4)
» Slack bytes
.CSECT
» control sections: RO(read-only data), RW(read-write data), P
R(executable instructions), BS(uninitialized read/write data)
» dummy section
17