Unit Ii Assemblers
Unit Ii Assemblers
Unit Ii Assemblers
ASSEMBLERS
ASSEMBLERS
OUTLINE
2.1 Basic Assembler Functions
◦ A simple SIC assembler
◦ Assembler tables and logic
2.2 Machine-Dependent Assembler Features
◦ Instruction formats and addressing modes
◦ Program relocation
2.3 Machine-Independent Assembler Features
2.4 Assembler Design Options
◦ Two-pass
◦ One-pass
◦ Multi-pass
2.1 BASIC ASSEMBLER FUNCTIONS
Figure 2.1 shows an assembler language program
for SIC.
◦ The line numbers are for reference only.
◦ Indexing addressing is indicated by adding the
modifier “,X”
◦ Lines beginning with “.”contain comments only.
◦ Reads records from input device (code F1)
◦ Copies them to output device (code 05)
◦ At the end of the file, writes EOF on the output
device, then RSUB to the operating system
2.1 BASIC ASSEMBLER FUNCTIONS
Assembler directives (pseudo-
instructions)
◦ START, END, BYTE, WORD, RESB,
RESW.
◦ These statements are not translated into
machine instructions.
◦ Instead, they provide instructions to the
assembler itself.
2.1 BASIC ASSEMBLER FUNCTIONS
Data transfer (RD, WD)
◦ A buffer is used to store record
◦ Buffering is necessary for different I/O rates
◦ The end of each record is marked with a null
character (0016)
◦ Buffer length is 4096 Bytes
◦ The end of the file is indicated by a zero-length
record
◦ When the end of file is detected, the program
writes EOF on the output device and terminates
by RSUB.
Subroutines (JSUB, RSUB)
◦ RDREC, WRREC
◦ Save link (L) register first before nested jump
2.1.1 A SIMPLE SIC ASSEMBLER
Figure 2.2 shows the generated object code for
each statement.
◦ Loc gives the machine address in Hex.
◦ Assume the program starting at address 1000.
Translation functions
◦ Translate STL to 14.
◦ Translate RETADR to 1033.
◦ Build the machine instructions in the proper
format (,X).
◦ Translate EOF to 454F46.
◦ Write the object program and assembly listing.
Figure 2.2: Program from figure 2.1 with object code
2.1.1 A simple SIC Assembler
A forward reference
◦ 10 1000 FIRST STL RET ADR 141033
◦ A reference to a label (RETADR) that is defined
later in the program
◦ Most assemblers make two passes over the
source program
Most assemblers make two passes over source
program.
◦ Pass 1 scans the source for label definitions and
assigns address (Loc).
◦ Pass 2 performs most of the actual translation.
2.1.1 A SIMPLE SIC ASSEMBLER
Forward reference
Reference to a label that is defined later
in the program.
2.1.1 A SIMPLE SIC ASSEMBLER
The object program (OP) will be loaded into memory for
execution...
Three types of records..
◦ Header: program name, starting address, length...
◦ Text: starting address, length, object code...
◦ End: address of first executable instruction.
2.1.1 A SIMPLE SIC ASSEMBLER
2.1.1 A SIMPLE SIC ASSEMBLER
The symbol ^ is used to separate
fields.
Figure 2.31
E(H)=30(D)=16(D)+14(D)
Need 2 passes
2.3.2 SYMBOL-DEFINING
STATEMENTS
All symbols used to specify new location
counter value must have been previously
defined.
ORG ALPHA
BYTE1 RESB 1
BYTE2 RESB 1
BYTE3 RESB 1
ORG
ALPHA RESW 1
Forward reference
ALPHA EQU BETA
BETA EQU DELTA
DELTA RESW 1
Need 3 passes
2.3.3 EXPRESSIONS
Allow arithmetic expressions formed
◦ Using the operators +, -, ×, /.
◦ Division is usually defined to produce an integer
result.
◦ Expression may be constants, user-defined symbols,
or special terms.
106 1036 BUFEND EQU *
◦ Gives BUFEND a value that is the address of the next
byte after the buffer area.
Absolute expressions or relative expressions
◦ A relative term or expression represents some value
(S+r), S: starting address, r: the relative value.
2.3.3 EXPRESSIONS
107 1000 MAXLEN EQU BUFEND-BUFFER
◦ Both BUFEND and BUFFER are relative terms.
◦ The expression represents absolute value: the difference between the two
addresses.
◦ Loc =1000 (Hex)
◦ The value that is associated with the symbol that appears in the source
statement.
◦ BUFEND+BUFFER, 100-BUFFER, 3*BUFFER represent neither
absolute values nor locations.
Symbol tables entries
2.3.4 PROGRAM BLOCKS
The source program logically contained main,
subroutines, data areas.
◦ In a single block of object code.
More flexible (Different blocks)
◦ Generate machine instructions (codes) and data
in a different order from the corresponding
source statements.
Program blocks
◦ Refer to segments of code that are rearranged
within a single object program unit.
Control sections
◦ Refer to segments of code that are translated into
independent object program units.
2.3.4 PROGRAM BLOCKS
Three blocks, Figure 2.11
◦ Default (USE), CDATA (USE CDATA), CBLKS
(USE CBLKS).
Assembler directive USE
◦ Indicates which portions of the source program blocks.
◦ At the beginning of the program, statements are
assumed to be part of the default block.
◦ Lines 92, 103, 123, 183, 208, 252.
Each program block may contain several separate
segments.
◦ The assembler will rearrange these segments to gather
together the pieces of each block.
Main
RDREC
WRREC
Use EQU, any symbol used on the RHS be defined previously in the
source.
LOC Pass1 2 3
1000 LDA #0 1000 1000 1000
1003 ALPHA EQU BETA ???? ???? 1003
1003 BETA EQU DELTA ???? 1003 1003
1003 DELTA RESW1 1003 1003 1003
◦ Need 3 passes!
Figure 2.21, multi-pass assembler
(a)
2.4.3 MULTI-PASS ASSEMBLERS
(b)
2.4.3 MULTI-PASS ASSEMBLERS
(c)
2.4.3 MULTI-PASS ASSEMBLERS
(d)
2.4.3 MULTI-PASS ASSEMBLERS
(e)
2.4.3 MULTI-PASS ASSEMBLERS
(f)