0% found this document useful (0 votes)
9 views

Module 1 Chapter 2 3 Assembler and Loader

Uploaded by

pallavi r
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Module 1 Chapter 2 3 Assembler and Loader

Uploaded by

pallavi r
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 115

Module -1

Chapter 1, 2 &3
Assembler & Loader

Pallavi R, Assistant Professor, CSE, KSIT 1


Topics to cover
1. Basic Assembler Function
2. Assembler Algorithms and Data Structures
 Machine-Dependent Assembler Features
 Instruction formats and addressing modes
 Program relocation
 Problems on object code Generation in Sic and
SIC/XE
3. Machine-Independent Assembler Features
4. Assembler Design Options
 Two-pass
 One-pass
 Multi-pass
3.1 Loader and Linker

Pallavi R, Assistant Professor, CSE, KSIT 2


Definition of
Assembler
• An assembler is a kind of translator that accepts the input in
assembly program and produces its
language language machine

equivalent.

Ex: MASM, TASM

Pallavi R, Assistant Professor, CSE, KSIT 3


Basic Assembler Functions
1. Convert mnemonic operations code to machine language .

Ex: STL14, JSUB48

2. Convert symbolic (labels) operands to their equivalent machine


address.

Ex: Cloop 100

3. Build machine instruction in the proper format.

4.Convert the data constant to internal machine representation.

Ex: EF4546
5. Write the object program.

Pallavi R, Assistant Professor, CSE, KSIT 4


Assembler Directives

• They provide the instruction to assembler.

• They are not translated into machine operation code.

START,END,BYTE,WORD,RESB,RESW

Pallavi R, Assistant Professor, CSE, KSIT 5


Assembler Directives

START: Specify name and starting address for the program.

END: Indicate the end of the source and specify the


first executable instruction in the program.

BYTE: Generate character or hexadecimal constant occupying as


many bytes as needed to represent the constant.

WORD: Generate one-word integer constant.

RESB: Reserves the indicated number of bytes for a data area.

RESW: Reserves the indicated number of words for a data area.

Pallavi R, Assistant Professor, CSE, KSIT 6


Assembler Algorithms and Data
Structures
Data structures.
 OPTAB (operation table)
 SYMTAB (symbol table)
 LOCCTR(Location Counter)

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 .

 Initially LOCCTR is initialized START statement.

 Pass 1 Algorithm: usually writes an inter-mediate file that contains each source statement

together with its assigned address, error indicators, etc.

 This file is used as the input to Pass 2.

Pallavi R, Assistant Professor, CSE, KSIT 8


OPTAB (Operation Table)
 It is also one of the internal Data structure.
 It is used to look up mnemonic operation code and translate them to their
machine language equivalent.
 During pass 1, OPTAB is used to look up and validate operation codes in
the source program.
 During pass 2, it is used to translate the operation codes to
machine
language.
 For SIC/XE machine, that has instruction of different format, to find the
instruction length for incrementing LOCCTR.
 OPTAB is usually organized as a hash table, with mnemonic operation
code as the key.
 In most cases, OPTAB is a static table – that is, entries are not normally
added to or deleted from it.

Pallavi R, Assistant Professor, CSE, KSIT 9


SYMTAB (Symbol Table)
• It is also internal data structures in assembler.
• SYMTAB is used to store values assigned to labels.
• SYMTAB includes the name and value (address) for each label in the source
program, together with flags to indicate error condition (e.g., a symbol defined in
two different places).
• This table also contain other information about data area.
• During Pass 1, labels are entered into SYMTAB as they are encountered in the
source program, along with their assigned addresses (from LOCCTR).
• During Pass 2, symbols used as operands are looked up in SYMTAB to obtain
the addresses to be inserted in the assembled instruction.
• SYMTAB is usually organized as a hash table for efficiency of insertion and
retrieval.
Pallavi R, Assistant Professor, CSE, KSIT 10
Functions of the two passes assembler.

• Pass 1 (define symbol)


 Assign addresses to all statements (generate LOC).
 Save the values (address) assigned to all labels for Pass 2.
 Perform some processing of assembler directives.
• Pass 2
Assemble instructions.
Generate data values defined by BYTE, WORD.
Perform processing of assembler directives not done during
Pass 1.
Write the object program and the assembly listing .

Pallavi R, Assistant Professor, CSE, KSIT 11


Pallavi R, Assistant Professor, CSE, KSIT 12
PASS-1 Assembler
Algorithm

Pallavi R, Assistant Professor, CSE, KSIT 13


Pass-1-Continue..

Pallavi R, Assistant Professor, CSE, KSIT 14


Pass-1-Continue..

Pallavi R, Assistant Professor, CSE, KSIT 15


PASS-2 Assembler
Algorithm

Pallavi R, Assistant Professor, CSE, KSIT 16


Pass2-Continue..

Pallavi R, Assistant Professor, CSE, KSIT 17


PASS-2 Continue..

Pallavi R, Assistant Professor, CSE, KSIT 18


Object Program

• The object program (OP) will be loaded into memory


for execution.
• Three types of records

Header Record: program name, starting address, length.

Text Record: starting address, length, object code.

End Record: address of first executable instruction.

Pallavi R, Assistant Professor, CSE, KSIT 19


Records Formats

Pallavi R, Assistant Professor, CSE, KSIT 20


Pallavi R, Assistant Professor, CSE, KSIT 21
2.2 Machine-Dependent Assembler
Features
• Problems on both SIC and SIC/XE machine
• Theory on instruction format and addressing modes , object
program .
• SIC/XE
– PC-relative/Base-relative addressing op m
– Indirect addressing op @m
– Immediate addressing op #c
– Extended format +op m
– Index addressing op m, X
– register-to-register instructions COMPR
– larger memory → multi-programming (program
allocation)

Pallavi R, Assistant Professor, CSE, KSIT 22


1.Generate the complete object program for the following assembly language program
.Assume standard SIC machine and the following machine codes in hexa and also
indicate the content of symbol at the end.LDA=00,LDX=04,
STA=0C,ADD=18,TIX=2C,JLT=38,RSUB=4C

Pallavi R, Assistant Professor, CSE, KSIT 23


Object Code Creation
Line LOCATION LABEL OPCODE Operand Object
no COUNTER code
1 SUM START 4000(h) -
2 4000 FIRST LDX ZERO 045788
3 4003 LDA ZERO 005788
4 4006 LOOP ADD TABLE,X 18CO15
5 4009 TIX COUNT 2C5785
6 400C JLT LOOP 384006
7 400F STA TOTAL 0C578B
8 4012 RSUB 4C0000
9 4015 TABLE RESW 2000 -
10 5785 COUNT RESW 1 -
11 5788 ZERO WORD 0 000000
12 578B TOTAL RESW 1 -
13 578E Prof. Maya B S, Assistant oEfeNssDor, FIRST -
24
Pr
CSE,BIT
OBJECT CODE CALCULATION in SIC
1. Instruction format -3bytes(24 bits)
Opcode(8 bit) X(1) Disp(12)

2. SIC add 3 byte to location counter


3. RESWconvert 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 25
Object Code Calculation
• First ZERO 04(opcode)
LDX 5788(address)

• Symbol table
SYMBOL Address
FIRST 4000
LOOP 4006
TABLE 4015
COUNT 5785
ZERO 5788
TOTAL 578B

Pallavi R, Assistant Professor, CSE, KSIT 26


Object program

•Using records write the object program


H^SUM_ _ _^004000^00178E
T^004000^15^045788^005788^18C015^2C5785^3840
06^0C578B^4C000
T^005788^000000
E^004000

Pallavi R, Assistant Professor, CSE, KSIT 27


2.Generate the complete object program for the following assembly
language
line
program Loc Label Opcode Operand Object code
1 SUM START 3000(H) -
2 3000 FIRST LDX ZERO 043180
3 3003 LDA THREE 003015
4 3006 LOOP ADD TABLE,X 18B018
5 3009 TIX COUNT 2C3144
6 300C JLT LOOP 383006
7 300F STA TOTAL 0C3183
8 3012 RSUB 4C0000
9 3015 THREE WORD 3 000003
10 3018 TABLE RESW 100 -
11 3144 COUNT RESW 20 -
12 3180 ZERO WORD 0 000000
13 3183 TOTAL RESW 1 -
14 3186 END FIRST -
Pallavi R, Assistant Professor, CSE, KSIT 28
OBJECT PROGRAM

• H^SUM- - -^003000^000186
• T^003000^18^043180^003015^18B018^2C3144^38
3006^0C3183^4C000^000003
• T^003180^03^000000
• E^003000

Pallavi R, Assistant Professor, CSE, KSIT 29


3. Object program for text book problem using SIC

• 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

• Subroutines (JSUB, RSUB)


– RDREC, WRREC

– Save link (L) register first before nested jump

Pallavi R, Assistant Professor, CSE, KSIT 30


• Below 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.

Pallavi R, Assistant Professor, CSE, KSIT 31


Pallavi R, Assistant Professor, CSE, KSIT 32
Pallavi R, Assistant Professor, CSE, KSIT 33
Pallavi R, Assistant Professor, CSE, KSIT 34
Object program

Header Record only one


Text Record any number depends on program length
End Record only one
H^COPY
^001000^00107A
T^001000^1E^142039^001036^………….^00102D
T^00101E^15^0c1036^…….^000000
T^002039^1E^041030^……^38203F
T^002057^1C^101036^….^2C1036
T^002073^D7^382064^4C0000^05
E^001000

Pallavi R, Assistant Professor, CSE, KSIT 35


• A forward reference
– 10 1000 FIRST STL RETADR
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.

Pallavi R, Assistant Professor, CSE, KSIT 36


Problems on SIC/XE machine
• Register translation
– register name (A, X, L, B, S, T, F, PC, SW) and their values (0, 1, 2, 3, 4,
5, 6, 8, 9)
– preloaded in SYMTAB

• 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

– Format 4: 20-bit address field (absolute addressing)


Pallavi R, Assistant Professor, CSE, KSIT 37
• The START statement
– Specifies a beginning address of 0.

• Register-register instructions
– CLEAR & TIXR, COMPR

• Register-memory instructions are using


– Program-counter (PC) relative addressing

– The program counter is advanced after each instruction is fetched and


before it is executed.
– PC will contain the address of the next instruction.

10 0000 FIRST STL RETADR 17202D

TA - (PC) = disp = 30 - 3 = 2D

Pallavi R, Assistant Professor, CSE, KSIT 38


1. Object program on SIC/XE machine

LINE LOC LABEL OPCODE OPERAND OBJECT CODE


1 WRREC START 105D

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. RESWconvert 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)

Pallavi R, Assistant Professor, CSE, KSIT 42


Object Program

• H^WRREC_^00105D^0001AC
• T^00105D^1A^00B410^7721a5^E32011^332F

FA^53A00C^DF2008^00B850^3B2FEF^4F000^
05
• E^00105D

Pallavi R, Assistant Professor, CSE, KSIT 43


2.Compute Object program on below SIC/XE machine

Pallavi R, Assistant Professor, CSE, KSIT 44


LINE LOC LABEL OPCODE OPERAND OBJECT
CODE
1 SUM START 0
2 FIRST LDX #0
3 LDA #0
4 +LDB #TABLE2
5 BASE TABLE2
6 LOOP ADD TABLE,X
7 ADD TABLE2,X
8 TIX COUNT
9 JLT LOOP
10 +STA TOTAL
11 RSUB
12 COUNT RESW 1
13 TABLE RESW 2000
14 TABLE2 RESW 2000
15 TOTAL RESW 1
16 Prof. Maya B S, Assist anEt NProDfessor, FIRST 46
CSE,BIT
Pallavi R, Assistant Professor, CSE, KSIT 46
OBJECT PROGRAM

H^SUM- - - ^000000^002F03
T^000000^1D^050000^010000^69101790^1BA013^1BC000^2F
200A^3B2FF4^0F102F00^4F0000
E^000000

Pallavi R, Assistant Professor, CSE, KSIT 47


3. Object program on text book problem using SIC/XE machine

• Indirect addressing
– Adding the prefix @ to operand (line 70).

• Immediate operands
– Adding the prefix # to operand (lines 12, 25, 55, 133).

• Base relative addressing


– Assembler directive BASE (lines 12 and 13).

• Extended format
– Adding the prefix + to OP code (lines 15, 35, 65).

• The use of register-register instructions.


– Faster and don’t require another memory reference.

Pallavi R, Assistant Professor, CSE, KSIT 48


Pallavi R, Assistant Professor, CSE, KSIT 49
Pallavi R, Assistant Professor, CSE, KSIT 50
Pallavi R, Assistant Professor, CSE, KSIT 51
1. 40 0017 J CLOOP
0006 - 001A = disp = - 3F2FEC
14 (represent 2’s complement)
2. Base (B), LDB #LENGTH, BASE LENGTH
160 104E STCH BUFFER, X 57C003
TA-(B) = 0036 - (B) = disp = 0036-0033 =
0003
3.Extended instruction
15 0006 +JSUB RDREC 4B101036
CLOOP

4.55Immediate
0020 LDA #3 010003
instruction
133103C +LDT #4096 75101000

5. PC relative + indirect addressing (line


70)

Pallavi R, Assistant Professor, CSE, KSIT 52


Program Relocation(VVIMP)

• In a typical multiprogramming environment where multiple programs can


run simultaneously , there is no guarantee that program will get loaded at a
particular memory location as mentioned in the program.

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

Pallavi R, Assistant Professor, CSE, KSIT 53


Program Relocation

Pallavi R, Assistant Professor, CSE, KSIT 56


56
• Modification record (direct addressing)
– 1 M
– 2-7 Starting location of the address field to be
modified, relative to the beginning of the program.
– 8-9 Length of the address field to be modified, in half
bytes.

M^0000007^05

Pallavi R, Assistant Professor, CSE, KSIT 58


58
2.3 Machine independent Assembler
Features

Pallavi R, Assistant Professor, CSE, KSIT 56


2.3.1 Literals
• Literals are the value given to the constant.
• Literals are always prefix with “=“
• Normally the literals are always stored at the end of the
program.
• Suppose if we want to store in middle of the program we need
use a LTORG .
• LTORG contains all the literals used till the LTORG
encounters in the program (Literal Pool).

• Literals will be stored in the table called LITTABLE


• LITTABLE Consits: Literal name, Value, length, address .

Pallavi R, Assistant Professor, CSE, KSIT 57


NOT LITERALS:
LDA FIVE
STA STORE
LDA SIX
JLT ELEVEN
FIVE WORD 5
LITERALS:
LDA = X’5’
STA STORE
LTORG
=X’5’
LDA SIX
JLT ELEVEN
Pallavi R, Assistant Professor, CSE, KSIT 59
Literals-Continue

• Literal table (LITTAB)


– Pass 1, the assembler searches LITTAB for the specified literal name. if
it is not found , particular literal name will be added to the LITTABLE.
– Address will be specified during the LTORG.

– Pass 2, generates Object Code

Pallavi R, Assistant Professor, CSE, KSIT 60


2.3.2 Symbol-Defining Statements

• Two assembler directives are used


• EQU
• ORG
1. EQU
It defines the symbol along with the value .

Syntax: SYMBOL EQU VALUE


EX:
Maxlen EQU 4096
Program:
LDA #4096
STA STORE
Can be written as
Maxlen EQU 4096
LDA #Maxlen
STA STORE
Pallavi R, Assistant Professor, CSE, KSIT 61
Symbol-Defining Statements

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

Pallavi R, Assistant Professor, CSE, KSIT 68


68
2.3.3 Expressions
Two kind of expressions
• Absolute Expression
• Relative Expression

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

Pallavi R, Assistant Professor, CSE, KSIT 63


2.3.4 Program Blocks

• Three blocks, Figure 2.11


 Default, CDATA, 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.

Pallavi R, Assistant Professor, CSE, KSIT 64


Main

Pallavi R, Assistant Professor, CSE, KSIT 65


RDREC

Pallavi R, Assistant Professor, CSE, KSIT 66


WRREC

Pallavi R, Assistant Professor, CSE, KSIT 67


Program Blocks-continue
• Pass 1, Figure 2.12
 A separate location counter for each program block.

 The location counter for a block is initialized to 0 when the block is


first begun.
 Assign each block a starting address in the object program (location 0).

 Labels, block name or block number, relative address

 Working table

Block name Block number Address Length


(default) 0 0000 0066 (0~65)

CDATA 1 0066 000B (0~A)

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

• Pass 2, Figure 2.12


– The assembler needs the address for each symbol relative to the start of
the object program.
– Loc shows the relative address and block number.

– Notice that the value of the symbol MAXLEN (line 70) is


shown
without a block number.

20 0006 0 LDA LENGTH 032060

0003(CDATA) +0066 =0069 =TA

using program-counter relative addressing

TA - (PC) =0069-0009 =0060 =disp


Pallavi R, Assistant Professor, CSE, KSIT 72
Program Blocks

• Separation of the program into blocks.


 Because the large buffer is moved to the end of the object program.
 No longer need extended format, base register, simply a
LTORG
statement.
 No need Modification records.
 Improve program readability.
• Figure 2.13
 Reflect the starting address of the block as well as the relative location of
the code within the block.
• Figure 2.14
 Loader simply loads the object code from each record at the dictated.
 CDATA(1) & CBLKS(1) are not actually present in Object program.

Pallavi R, Assistant Professor, CSE, KSIT 73


Program Blocks-object program

Pallavi R, Assistant Professor, CSE, KSIT 74


Pallavi R, Assistant Professor, CSE, KSIT 75
2.3.5 Control Sections & Program Linking

• Control section
 Handling of programs that consist of multiple control sections.

 A part of the program.

 Can be loaded and relocated independently.

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

 Linking control sections together.


Pallavi R, Assistant Professor, CSE, KSIT 76
Control Sections & Program Linking

• 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

Pallavi R, Assistant Professor, CSE, KSIT 77


Pallavi R, Assistant Professor, CSE, KSIT 78
Pallavi R, Assistant Professor, CSE, KSIT 79
Pallavi R, Assistant Professor, CSE, KSIT 80
Control Sections & Program Linking
• Figure 2.16, the generated object code.

15 0003 CLOOP+JSUB RDREC 4B100000

160 0017 +STCH BUFFER,X 57900000


 RDREC is an external reference.

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

 Must use extended format instruction for external reference (M


records are needed).

190 0028 MAXLEN WORD BUFEND-BUFFER


 An expression involving two external references.
Pallavi R, Assistant Professor, CSE, KSIT 81
Pallavi R, Assistant Professor, CSE, KSIT 82
Pallavi R, Assistant Professor, CSE, KSIT 83
Pallavi R, Assistant Professor, CSE, KSIT 84
Control Sections & Program Linking
 The loader will add to this data area with the address of BUFEND and
subtract from it the address of BUFFER. (COPY and RDREC)
 Line 190 and 107, in 107, the symbols BUFEND and BUFFER
are defined in the same section.
 The assembler must remember in which control section a symbol is
defined.
 The assembler allows the same symbol to be used in different control
sections, lines 107 and 190.
• Figure 2.17, two new records.
 Defined record for EXTDEF, relative address.

 Refer record for EXTREF.


Pallavi R, Assistant Professor, CSE, KSIT 85
Pallavi R, Assistant Professor, CSE, KSIT 86
Control Sections & Program Linking
• Modification record
– M
– Starting address of the field to be modified, relative to the beginning
of the control section (Hex).
– Length of the field to be modified, in half-bytes.
– Modification flag (+ or -).
– External symbol.
M^000004^05+RDREC
M^000028^06+BUFEN
D M^000028^06-
BUFFER
• Use Figure 2.8 for
program relocation.

Pallavi R, Assistant Professor, CSE, KSIT 98


98
Pallavi R, Assistant Professor, CSE, KSIT 88
Pallavi R, Assistant Professor, CSE, KSIT 89
2.4 Assembler Design
Options
2.4.1 Two-Pass Assembler
• Most assemblers
 Processing the source program into two passes.

 The internal tables and subroutines that are used only during Pass 1.

 The SYMTAB, LITTAB, and OPTAB are used by both passes.

• The main problems to assemble a program in one pass involves


forward
references.

Pallavi R, Assistant Professor, CSE, KSIT 90


ASSEMBLER DESIGN OPTION

TWO PASS ASSEMBLER SINGLE PASS ASSEMBLER MULTI PASS ASSEMBLER


Two pass is required to Single pass is enough to More than Two pass is
convert assembly to convert assembly to required to convert
machine language machine language assembly to machine
language

Procedure used is Procedure used is Load


Forward Reference and Go
2.4.2 One-Pass
Assemblers
• Eliminate forward references
 Data items are defined before they are referenced.

 But, forward references to labels on instructions cannot be eliminated


as easily.
 Prohibit forward references to labels.

• Two types of one-pass assembler. (Fig. 2.18)


 One type produces object code directly in memory for
immediate execution.
 The other type produces the usual kind of object program for
later
execution.
Pallavi R, Assistant Professor, CSE, KSIT 92
Pallavi R, Assistant Professor, CSE, KSIT 93
Pallavi R, Assistant Professor, CSE, KSIT 94
Pallavi R, Assistant Professor, CSE, KSIT 95
One-Pass

Assemblers
Load-and-go one-pass assembler
 The assembler avoids the overhead of writing the object program out
and reading it back in.
 The object program is produced in memory, the handling of
forward
references becomes less difficult.
 Figure 2.19(a), shows the SYMTAB after scanning line 40
of the program in Figure 2.18.
 Since RDREC was not yet defined, the instruction was assembled
with
no value assigned as the operand address (denote by ----).

Pallavi R, Assistant Professor, CSE, KSIT 96


Pallavi R, Assistant Professor, CSE, KSIT 97
One-Pass
Assemblers
• Load-and-go one-pass assembler
 RDREC was then entered into SYMTAB as an undefined symbol, the
address of the operand field of the instruction (2013) was inserted.
 Figure 2.19(b), when the symbol ENDFIL was defined (line 45), the
assembler placed its value in the SYMTAB entry; it then inserted this
value into the instruction operand field (201C).
 At the end of the program, all symbols must be defined without any
*
in SYMTAB.
 For a load-and-go assembler, the actual address must be known at
assembly time.
Pallavi R, Assistant Professor, CSE, KSIT 98
One-Pass
Assemblers
• Another one-pass assembler by generating OP
 Generate another Text record with correct operand address.

 When the program is loaded, this address will be into


the
inserted instruction by the action of the loader.
 Figure 2.20, the operand addresses for the instructions on lines 15, 30,
and 35 have been generated as 0000.
 When the definition of ENDFIL is encountered on line 45, the third Text
record is generated, the value 2024 is to be loaded at location 201C.
 The loader completes forward references.

Pallavi R, Assistant Professor, CSE, KSIT 99


Pallavi R, Assistant Professor, CSE, KSIT 100
One-Pass
Assemblers

• In this section, simple one-pass assemblers


handled absolute programs (SIC example).

Pallavi R, Assistant Professor, CSE, KSIT 101


2.4.3 Multi-Pass
Assemblers
• Use EQU, any symbol used on the RHS be defined previously in
the source.
ALPHA EQU BETA
BETA EQU
DELTA DELTA
– Need 3RESW
passes!1
• Figure 2.21, multi-pass assembler

Pallavi R, Assistant Professor, CSE, KSIT 102


112
Multi-Pass
Assemblers
• Problem-step1

Pallavi R, Assistant Professor, CSE, KSIT 103


112
Multi-Pass
Assemblers
• Problem-step2

Pallavi R, Assistant Professor, CSE, KSIT 104


112
Multi-Pass
Assemblers
• Problem-step3

Pallavi R, Assistant Professor, CSE, KSIT 105


112
Multi-Pass
Assemblers
• Problem-step4

Pallavi R, Assistant Professor, CSE, KSIT 106


112
Multi-Pass
Assemblers

Pallavi R, Assistant Professor, CSE, KSIT 107


112
Basic Loader Functions
• In Assembler, we discussions
 Loading: brings the OP into memory for execution

 Relocating: modifies the OP so that it can be loaded at an address


different form the location originally specified.
 Linking: combines two or more separate OP

• In Loaders, we will discussion


A loader brings an object program into memory and
startingits
execution.
 A linker performs the linking operations and a separate loader to
handle relocation and loading.
Pallavi R, Assistant Professor, CSE, KSIT 108
BASIC LOADER

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.

Pallavi R, Assistant Professor, CSE, KSIT 110


Algorithm for Absolute
loader(VVIMP)

Pallavi R, Assistant Professor, CSE, KSIT 111


A Simple Bootstrap

Loader
A bootstrap loader, Figure 3.3.
 Loads the first program to be run by the computer---
usuallyan operating system.
 The bootstrap itself begins at address 0 in the memory.

 It loads the OS or some other program starting at address 80

 Each byte of object code to be loaded is represented on device F1


as two Hex digits (by GETC subroutines).
 The ASCII code for the character 0 (Hex 30) is converted
to the
numeric value 0.
 The object code from device F1 is always loaded into consecutive bytes
of memory, startingPallavi
at address 80.
R, Assistant Professor, CSE, KSIT 112
Algorithm for Bootstrap
loader(VVIMP)

Pallavi R, Assistant Professor, CSE, KSIT 113


Pallavi R, Assistant Professor, CSE, KSIT 114
THANK YOU

Pallavi R, Assistant Professor, CSE, KSIT 115

You might also like