Module 1 Chapter 2 3 Assembler and Loader
Module 1 Chapter 2 3 Assembler and Loader
Chapter 1, 2 &3
Assembler & Loader
equivalent.
Ex: EF4546
5. Write the object program.
START,END,BYTE,WORD,RESB,RESW
Algorithms:
PASS-1 Assembler
Algorithm PASS-2
Assembler Algorithm
Pallavi R, Assistant Professor, CSE, KSIT 7
Location Counter
It is used to allocate the address (location) to each instruction .
Pass 1 Algorithm: usually writes an inter-mediate file that contains each source statement
• Symbol table
SYMBOL Address
FIRST 4000
LOOP 4006
TABLE 4015
COUNT 5785
ZERO 5788
TOTAL 578B
• H^SUM- - -^003000^000186
• T^003000^18^043180^003015^18B018^2C3144^38
3006^0C3183^4C000^000003
• T^003180^03^000000
• E^003000
• Translation functions
– Translate STL to 14.
• Address translation
– Most register-memory instructions use program counter relative or base
relative addressing
– Format 3: 12-bit disp (address) field
• Base-relative: 0~4095
• PC-relative: -2048~2047
• Register-register instructions
– CLEAR & TIXR, COMPR
TA - (PC) = disp = 30 - 3 = 2D
2 CLEAR BUFFER
3 LDT LENGTH
4 WLOOP TD OUTPUT
5 JEQ WLOOP
6 LDCH BUFFER,X
7 WD OUTPUT
8 TIXR T
9 JLT WLOOP
10 RSUB
11 OUTPUT BYTE X’05’
12 BUFFER RESB 400
13 LENGTH RESB 2
39
14 Prof. Maya B S, taEnNt WIT RREC
,B
LINE LOC LABEL OPCODE OPERAND OBJECT
CODE
1 WRREC START 105D -
2 105D CLEAR X B410
3 105F LDT LENGTH 7721A5
4 1062 WLOOP TD OUTPUT E32011
5 1065 JEQ WLOOP 332FFA
6 1068 LDCH BUFFER,X 53A00C
7 106B WD OUTPUT DF2008
8 106E TIXR T B850
9 107D JLT WLOOP 3B2FEF
10 1073 RSUB 4F0000
11 1076 OUTPUT BYTE X’05’ 05
12 1077 BUFFER RESB 400 -
13 1207 LENGTH RESB 2 -
14 1209 Prof. Maya B S, Ass istEaNnt DProfessor, ITWRREC - 40
CSE,B
OBJECT CODE CALCULATION in SIC/XE
1. Instruction format -4 TYPES
-Depends on types add the length of instruction to location counter(1byte,2bytes,3
bytes,4 bytes)
2. SIC/X add 4 byte to location counter when instruction preceding with + symbol.
3. RESWconvert decimal to hexa decimal
LOC= LOC+3*#[operand]
=4015+3*2000(d)
=4015+3*7D0(d)
=4015+1770
=5785
3. WORD add 3 byte to
location counter
4. RESB Conver
decimal to hexadecimal
LOC=LOC+#[operand]
5. BYTE count the
number of character in
operand field and add Pallavi R, Assistant Professor, CSE, KSIT 41
that number to
Object code calculation
1. Check the instruction format
2. If format 3 , check program counter relative address and base
relative address for displacement calculation.
3. Format and format 2 not required address.
4. Remember the n and i bit . # (n=0, i=1 ), @(n=1, i=0)
5. Remember the mnemonic number of register
6. EX: CLEAR X b410 (clear-B4)(X=1) (r2-
absent)
• H^WRREC_^00105D^0001AC
• T^00105D^1A^00B410^7721a5^E32011^332F
FA^53A00C^DF2008^00B850^3B2FEF^4F000^
05
• E^00105D
H^SUM- - - ^000000^002F03
T^000000^1D^050000^010000^69101790^1BA013^1BC000^2F
200A^3B2FF4^0F102F00^4F0000
E^000000
• Indirect addressing
– Adding the prefix @ to operand (line 70).
• Immediate operands
– Adding the prefix # to operand (lines 12, 25, 55, 133).
• Extended format
– Adding the prefix + to OP code (lines 15, 35, 65).
4.55Immediate
0020 LDA #3 010003
instruction
133103C +LDT #4096 75101000
• Rather, to load a program into memory whenever there is a room for it , the
actual starting address of the program is not known until load time, only
loader knows this.
• The above concept is called as program relocation .
M^0000007^05
2. ORG.
ORG is used to change Address of LOCCTR to
specified value.
Ex: SUM START 3000 : LOOCTR=> 3000
TDA #5 :LOCCTR=> 3003
ORG 3045 :LOCCTR=> 3045
TIX ELEVEN
Absolute Expression :
Actual value which can be used to perform arithmetic
operations.
EX: LDA #5
ADD #6
Relative Expression:
Value changes according to the address
EX: SUM START 1000
BUFFER+3
Working table
CBLKS 2 0071
Pallavi R, Assistant Professor, CSE, KSIT
1000 (0~0FFF) 68
Pallavi R, Assistant Professor, CSE, KSIT 69
Pallavi R, Assistant Professor, CSE, KSIT 70
Pallavi R, Assistant Professor, CSE, KSIT 71
Program Blocks
• Control section
Handling of programs that consist of multiple control sections.
Different control sections are most often used for subroutines or other
logical subdivisions of a program.
The programmer can assemble, load, and manipulate each of
these control sections separately.
Flexibility.
• External references
Instructions in one control section might need to refer to instructions or
data located in another section.
• Figure 2.15, multiple control sections.
Three sections, main COPY, RDREC, WRREC.
Assembler directive CSECT.
EXTDEF and EXTREF for external symbols.
The order of symbols is not significant.
COPY START 0
EXTDEF BUFFER, BUFEND, LENGTH
RDREC, WRREC
EXTREF
The assembler has no idea where the control section containing RDREC
will be loaded, so it cannot assemble the address.
The proper address to be inserted at load time.
The internal tables and subroutines that are used only during Pass 1.
SRC PRG -> ASSEMBLER -> OBJECT PRG -> LOADER -> MEMORY
Loader operations
Relocation
Linking
Types of Loader
• Absolute Loader
• Bootstrap Loader
Design of an Absolute
Loader
• Absolute loader, in Figures 3.1 and 3.2.
– Does not perform linking and program relocation.
– The contents of memory locations for which there is no Text record are
shown as xxxx.
– Each byte of assembled code is given using its Hex representation in
character form.