0% found this document useful (0 votes)
32 views33 pages

05 Assimpler2

The document discusses program relocation and machine-independent assembler features in systems programming. Program relocation allows a program to be loaded at different memory addresses by modifying address fields according to the loading address. The assembler generates modification records to instruct the loader to add the starting load address to address fields. Assemblers also support literals, symbols, and one-pass operation. One-pass assemblers handle forward references by listing them or filling addresses with placeholders until defined.

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views33 pages

05 Assimpler2

The document discusses program relocation and machine-independent assembler features in systems programming. Program relocation allows a program to be loaded at different memory addresses by modifying address fields according to the loading address. The assembler generates modification records to instruct the loader to add the starting load address to address fields. Assemblers also support literals, symbols, and one-pass operation. One-pass assemblers handle forward references by listing them or filling addresses with placeholders until defined.

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Systems Programming

Program Relocation
&
Machine Independent Assembler Features
Program relocation

 The above SIC program is an example of an absolute program (or


absolute assembly). If the absolute program started at 1000, it also
must be loaded at address 1000 in order to execute properly.
 Example: In the object program, line 55 is translated as 00102D,
specifying that register A is to be loaded from memory address
102D.
Program relocation

 Suppose we attempt to load and execute the program at address 2000


instead of address 1000. If we do this, address 102D will not contain the
value that we expect.
 In reality, the assembler does not know the actual location where the
program will be loaded.
 However, the assembler can identify for the loader those parts of the object
program that need modification.
 An object program that contains the information necessary to perform this
kind of modification is called a relocatable program.
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)

 the length field of a modification record is stored in half-


bytes (rather than bytes) because the address field to be
modified may not occupy an integral number of bytes.
 For example, the address field in the +JSUB occupies 20
bits.
Program relocation
 Example: the modification record for the +JSUB instruction would be
“M^000007^05”
 This record specifies that the beginning address of the program is to
be added to a field that begins at address 000007 (relative to the
start of the program as the start address of this instruction is 0006
and the opcode size is approximately one byte,
 then the leftmost bits of the address field starts at 1+6=7) and is 5
half-bytes in length.
Program relocation

 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

 Literal VS. Immediate operand


 With immediate addressing, the operand value is assembled as part of the machine
instruction.
 With a literal, the assembler generates the specified value as a constant at some
other memory location.
 All of the literal operands used in a program are gathered together into one or more
literal pools.
 Normally literals are placed into a pool at the end of the program. (See target code)
Literals

 In some cases, it is desirable to place literals into a pool at some other


location in the object program. To allow this, we introduce the assembler
directive LTORG (line 93).
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.

 The basic data structure that assembler handles literal operands is


literal table LITTAB. For each literal used, this table contains the literal
name, the operand value and length, and the address assigned to the
operand when it is placed in a literal pool.
Symbol defining statements

 Most assembler provide directive allows the programmers to define symbols


Symbol EQU value
 symbol enters SYMTAB with its value
 It improves readability
+LDT #4096
 Can be written as
MAXLEN EQU 4096
+LDT # MAXLEN
 Another use of EQU is to give names to registers
A EQU 0
X EQU 0
L EQU 2
Symbol defining statements

.
.
 Another directive called ORG is used
ORG value

 The assembler resets LOCCTR to the specified value


 Be carful using ORG
Symbol defining statements

 SYMBOL contains 6 bytes


 VALUE contains 1 word
 FLAGS contains 2 bytes

 This method does not make the structure of the table clear
Symbol defining statements

 Another method using ORG

 The 1st ORG resets LOCCTR to the value of STAB


 The last ORG sets the LOCCTR back to its previous value
Systems Programming

Assembler design options


One Pass Assembler

 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

 Produces object code directly in memory for immediate execution


 No separate loader
 No object file created
 The challenge is to deal with forward reference
Load-and-Go Assembler

 SIC program called ‘Copy’


Load-and-Go Assembler

 The labels EOF, THREE, ZERO, RETADR, LENGTH, BUFFER are all
backward reference because they defined before used

 E.g. THE INSTRUCTION IN LINE 10


FIRST STL RETADR
 the assembler already now know RETADR value
 So it is easy for the Assembler to generate the object code for this
line which is 141009
 The address is 1009
Load-and-Go Assembler

 The next instruction at line 15


CLOOP JSUB RDREC

 RDREC is a forward reference (the label appears after the


instruction)
 So, it will assemble the instruction as follows 480000 where 48 is the
op code and the value of RDREC putted zeros for now
 The same for instruction in the line 30
JEQ ENDFIL
 it will be assembled as 30 0000
 where 30 is the op code and endfil is putted 4 zeros for now
Load-and-Go Assembler

 Symbol table will have the following entries after line 30

SYMBOL VALUE LINE NO.


EOF 1000
THREE 1003
ZERO 1006
RETADR 1009
LENGTH 100C
BUFFER 100F
RDREC 0000 UPDATE AT location (2013)
ENDFIL 0000  UPDATE AT location (201C) At line 30
Load-and-Go Assembler

 Symbol table will have the following entries after line 45


 The object code at location 201C will be updated from
300000  302024
SYMBOL VALUE LINE NO.
EOF 1000
THREE 1003
ZERO 1006
RETADR 1009
LENGTH 100C
BUFFER 100F
0000  UPDATE AT
RDREC
location (2013)
ENDFIL 2024 UPDATE AT Loc (201C)
Load-and-Go Assembler

 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

 Forward references are entered into lists as before


 When instruction made Forward references the assembler puts
zeros in the address (in the text record)
 When the definition of the symbol is encountered the assembler
generate another text record with the correct object address
 It is the job of the LOADER to insert the correct address into the
instruction
One pass assembler producing object file

 The object code generated from line 10 to line 40 illustrated in


the second text record in the following fig
One pass assembler producing object file

 The object code generated from line 10 to line 40 illustrated in


the second text record in the following fig
One pass assembler producing object file

 When the definition of ENDFIL in line 45 is encountered the assembler


generate the 3rd text record
 It specifies that the value 2024 (ENDFIL address) is to be loaded in location
201C (operand address in line 30 of JEQ instruction)
Multi-pass Assembler

 Some Assemblers designed to eliminate the forward reference restriction by


using a multi-pass Assembler
 The following example shows that 2 pass assembler not enough
Multi-pass Assembler

 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.

You might also like