05 Assimpler2
05 Assimpler2
Program Relocation
&
Machine Independent Assembler Features
Program relocation
The following Fig. shows different places (0000, 5000, 7420) for
locating the above SIC/XE program.
For example, suppose that the address of RDREC is 1036(0000)in the
instruction “+JSUB RDREC”, 6036(5000), 8456(7420). How to modify
the address of RDREC according to different relocating address?
Program relocation
Program relocation
The solution to the relocation problem:
When the assembler generates the object code for JSUB instruction, it
will insert the address of RDREC relative to the start of the program.
(This is the reason why we initialized the location counter to 0 for the
assembly.)
The assembler will also produce a command for the loader, instructing
it to add the beginning address of the program to the address field in
the JSUB instruction at load time.
A modification record has the following format.
Program relocation
Col. 1 M
Col. 2-7 Starting location of the address field to be
modified, relative to the beginning of the
program (hexadecimal)
Col. 8-9 Length of the address field to be modified, in
half-bytes (hexadecimal)
Thus in the assembled instruction 4B101036, the first 12 bits (4B1) will
remain unchanged.
The program load address will be added to the last 20 bits (01036) to
produce the correct operand address.
In the program we have mentioned earlier, only lines 35 and 65 need to be
relocated. The rest of the instructions in the program need not be modified
when the program is loaded.
In some cases, this is because the instruction operand is not a memory address
at all (e.g., CLEAR R or LDA #3).
In other cases, no modification is needed because the operand is
specified using PC relative or base relative addressing.
Obviously, the only parts of the program that require modification at load time
are those that specify direct (Format 4) addresses.
Program relocation
The following Fig shows the complete object program.
Machine-Independent Assembler Features
Literals
It is often convenient for the programmer to be able to write the value of a
constant operand as a part of the instruction that uses it. The program that
illustrates the use of literals and the object code generated for the statements
of this program is shown below. (Note that, literal * denotes the location
counter)
Literals
Most assemblers recognize duplicate literals – that is, the same literal
used in more than one place in the program – and store only one
copy of the specified data value. For example, the literal =X’05’ is
used in our program on lines 215 and 230.
.
.
Another directive called ORG is used
ORG value
This method does not make the structure of the table clear
Symbol defining statements
Reads the Source program only once and translate it to object code
Two types of one pass assembler
1- Load-and-Go
2- Usual method
Load-and-Go Assembler
The labels EOF, THREE, ZERO, RETADR, LENGTH, BUFFER are all
backward reference because they defined before used
Symbol table will have the following entries after line 125
The object code at location 2013 will be updated from
480000 48203D
SYMBOL VALUE LINE NO.
EOF 1000
THREE 1003
ZERO 1006
RETADR 1009
LENGTH 100C
BUFFER 100F
RDREC 203D Update at 2013
ENDFIL 2024
One pass assembler producing object file
It is not necessary for such an assembler to make more than two passes over
the entire program.
Instead, the portions of the program that involve forward references in symbol
definition are saved during Pass 1.
Additional passes through these stored definitions are made as the assembly
progresses.
This process is followed by a normal Pass 2.