Vous êtes sur la page 1sur 62

Subject Name: SYSTEM SOFTWARE

Subject Code: 10CS52

Prepared By: Suganthi Sivakumar

Department: CSE

Date

SYSTEM SOFTWARE - UNIT II 1


SYSTEM
SOFTWARE
UNIT-II
Engineered for Tomorrow

SYSTEM SOFTWARE - UNIT II 2


ASSEMBLERS - I

Engineered for Tomorrow

SYSTEM SOFTWARE - UNIT II 3


Topic details
Assembler
Introduction
Assembler Directives
Assembler functions
Data Structures
Machine Dependant Assembler Features
Instruction format and Assembler Features
Program Relocation

SYSTEM SOFTWARE - UNIT II 4


Role of Assembler
Source Object
Linker
Assembler
Program Code

Executable
Code

Loader

SYSTEM SOFTWARE - UNIT II 5


Introduction
Fundamental functions
Translating mnemonic operation codes to their
machine language equivalents
Assigning machine addresses to symbolic labels

Machine dependency
Different machine instruction formats and codes

SYSTEM SOFTWARE - UNIT II 6


2.1 Assembler Directives
Pseudo-Instructions
Not translated into machine instructions
Providing information to the assembler
Basic assembler directives
START
END
BYTE
WORD
RESB
RESW

SYSTEM SOFTWARE - UNIT II 7


Example of a SIC Assembler Language
Program (3/1)

SYSTEM SOFTWARE - UNIT II 8


Example of a SIC Assembler Language
Program (3/2)

SYSTEM SOFTWARE - UNIT II 9


Example of a SIC Assembler Language
Program (3/3)

SYSTEM SOFTWARE - UNIT II 10


Example Program (Fig. 2.1)
Purpose
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

SYSTEM SOFTWARE - UNIT II 11


Example Program (Fig. 2.1)
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)
the end of the file is indicated by a zero-length record
Subroutines (JSUB, RSUB)
RDREC, WRREC
save link register first before nested jump

SYSTEM SOFTWARE - UNIT II 12


2.1.1 Assembler’s functions
Convert mnemonic operation codes to their machine
language equivalents
Convert symbolic operands to their equivalent machine
addresses
Build the machine instructions in the proper format
Convert the data constants to internal machine
representations
Write the object program and the assembly listing

SYSTEM SOFTWARE - UNIT II 13


Assembly Program with Object Code

Forward
reference

SYSTEM SOFTWARE - UNIT II 14


Assembly Program with Object Code

SYSTEM SOFTWARE - UNIT II 15


Assembly Program with Object Code

SYSTEM SOFTWARE - UNIT II 16


Forward Reference
Definition
A reference to a label that is defined later in the program
Solution
Two passes
First pass: scan the source program for label definition,
address accumulation, and address assignment
Second pass: perform most of the actual instruction
translation

SYSTEM SOFTWARE - UNIT II 17


Example
FIRST STL RETADR
---- ---- X--- ---- ---- ----
0001 0100 0001 0000 0011 0011141033

STCH BUFFER,X
---- ---- X--- ---- ---- ----
0101 0100 1001 0000 0011 1001549039

SYSTEM SOFTWARE - UNIT II 18


Object Program Format
Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address of object program (hex)
Col. 14-19 Length of object program in bytes (hex)
Text
Col.1 T
Col.2~7 Starting address for object code in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code, represented in hex (2 col. per byte)
End
Col.1 E
Col.2~7 Address of first executable instruction in object program (hex)
SYSTEM SOFTWARE - UNIT II 19
Fig. 2.3
H COPY 001000 00107A
T 001000 1E 141033 482039 001036 281030 301015 482061 ...
T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000
T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 …
T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 …
T 002073 07 382064 4C0000 05
E 001000

SYSTEM SOFTWARE - UNIT II 20


Example of Instruction Assemble
STCH BUFFER,X 549039
8 1 15
opcode x address
m
(54)16 1 (001)2 (039)16
Forward reference

SYSTEM SOFTWARE - UNIT II 21


Difficulties: Forward Reference
Forward reference: reference to a label that is defined later
in the program.

Loc Label Operator Operand

1000 FIRST STL RETADR


1003 CLOOP JSUB RDREC
… … … … …
1012 J CLOOP
… … … … …
1033 RETADR RESW 1

SYSTEM SOFTWARE - UNIT II 22


Two Pass Assembler
Pass 1
Assign addresses to all statements in the program
Save the values assigned to all labels for use in 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
in Pass 1
Write the object program and the assembly listing

SYSTEM SOFTWARE - UNIT II 23


Two Pass Assembler
Read from input line
LABEL, OPCODE, OPERAND

Source
program

Intermediate Object
Pass 1 Pass 2
file codes

OPTAB SYMTAB SYMTAB

SYSTEM SOFTWARE - UNIT II 24


2.1.2 Assembler Algorithm and Data
Structures
Operation Code Table (OPTAB)
Symbol Table (SYMTAB)
Location Counter(LOCCTR)

SYSTEM SOFTWARE - UNIT II 25


OPTAB (operation code table)
Content
menmonic, machine code (instruction format, length) etc.
Characteristic
static table
Implementation
array or hash table, easy for search

SYSTEM SOFTWARE - UNIT II 26


SYMTAB (symbol table)
Content COPY 1000
label name, value, flag, (type, length) etc. FIRST 1000
CLOOP 1003
Characteristic ENDFIL 1015
dynamic table (insert, delete, search) EOF 1024
THREE
Implementation 102D
hash table, non-random keys, hashing function ZERO 1030
RETADR 1033
LENGTH 1036
BUFFER 1039
RDREC 2039

SYSTEM SOFTWARE - UNIT II 27


LOCCTR
Used to help in the assignment of addresses
Initialized to the beginning address specified in the START
statement
After each source statement is processed, the length of the
assembled instruction or data area to be generated is added
Gives the address of a label

SYSTEM SOFTWARE - UNIT II 28


Pseudo Code for Pass 1

SYSTEM SOFTWARE - UNIT II 29


Pseudo Code for Pass 1

SYSTEM SOFTWARE - UNIT II 30


Pseudo Code for Pass 1

SYSTEM SOFTWARE - UNIT II 31


Pseudo Code for Pass 2

SYSTEM SOFTWARE - UNIT II 32


Pseudo Code for Pass 2

SYSTEM SOFTWARE - UNIT II 33


Pseudo Code for Pass 2

SYSTEM SOFTWARE - UNIT II 34


Machine-dependent
Assembler Features

Instruction formats and addressing modes


Program relocation

SYSTEM SOFTWARE - UNIT II 35


2.2.1 Instruction Format and Addressing
Mode
SIC/XE
PC-relative or 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
larger memory -> multi-programming (program allocation)

SYSTEM SOFTWARE - UNIT II 36


Translation
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 address field
base-relative: 0~4095
pc-relative: -2048~2047
Format 4: 20-bit address field
SYSTEM SOFTWARE - UNIT II 37
PC-Relative Addressing Modes

PC-relative
10 0000 FIRST STL RETADR 17202D

(14)16 1 1 0 0 1 0 (02D) 16
displacement= RETADR - PC = 30-3 = 2D
40 0017 J CLOOP 3F2FEC

(3C)16 11 001 0 (FEC) 16


displacement= CLOOP-PC= 6 - 1A= -14= FEC

SYSTEM SOFTWARE - UNIT II 38


BASE RELATIVE ADDRESSING MODE

Base-relative
base register is under the control of the programmer
12 LDB #LENGTH
13 BASE LENGTH
160 104E STCH BUFFER, X 57C003

( 54 )16 111100 ( 003 ) 16


(54) 1 1 1 0 1 0 0036-1051= -101B16
displacement= BUFFER - B = 0036 - 0033 = 3
NOBASE is used to inform the assembler that the contents of the base
register no longer be relied upon for addressing
SYSTEM SOFTWARE - UNIT II 39
Immediate Address Translation
Immediate addressing
◦ 55 0020 LDA #3 010003

( 00 )16 010000 ( 003 ) 16


◦ 133 103C +LDT #4096 75101000

( 74 )16 010001 ( 01000 ) 16

SYSTEM SOFTWARE - UNIT II 40


Immediate Address Translation(Cont.)
Immediate addressing
12 0003 LDB #LENGTH 69202D

( 68)16 010010 ( 02D ) 16


( 68)16 010000 ( 033)16 690033
the immediate operand is the symbol LENGTH
the address of this symbol LENGTH is loaded into register B
LENGTH=0033=PC+displacement=0006+02D
if immediate mode is specified, the target address becomes the
operand

SYSTEM SOFTWARE - UNIT II 41


Indirect Address Translation
Indirect addressing
target addressing is computed as usual (PC-relative or BASE-
relative)
only the n bit is set to 1
70 002A J @RETADR 3E2003

( 3C )16 100010 ( 003 ) 16

TA=RETADR=0030
TA=(PC)+disp=002D+0003

SYSTEM SOFTWARE - UNIT II 42


Example of SIC/XE Program(3/1)

SYSTEM SOFTWARE - UNIT II 43


Example of SIC/XE Program(3/2)

SYSTEM SOFTWARE - UNIT II 44


Example of SIC/XE Program(3/3)

SYSTEM SOFTWARE - UNIT II 45


Program with Object Code (3/1)

SYSTEM SOFTWARE - UNIT II 46


Object Code Translation
Format 3 op(6) n i x b p e disp(12)

Format 4 op(6) n i xbpe address(20)

Line 10: STL=14, n=1, i=1ni=3, op+ni=14+3=17,


RETADR=0030, x=0, b=0, p=1, e=0xbpe=2, PC=0003,
disp=RETADR-PC=030-003=02D, xbpe+disp=202D, obj=17202D
Line 12: LDB=68, n=0, i=1ni=1, op+ni=68+1=69,
LENGTH=0033, x=0, b=0, p=1, e=0xbpe=2, PC=0006,
disp=LENGTH-PC=033-006=02D, xbpe+disp=202D, obj=69202D

SYSTEM SOFTWARE - UNIT II 47


Object Code Translation
Format 3 op(6) n i x b p e disp(12)

Format 4 op(6) n i xbpe address(20)

Line 15: JSUB=48, n=1, i=1ni=3, op+ni=48+3=4B, RDREC=01036,


x=0, b=0, p=0, e=1, xbpe=1, xbpe+RDREC=101036, obj=4B101036
Line 40: J=3C, n=1, i=1ni=3, op+ni=3C+3=3F, CLOOP=0006, x=0,
b=0, p=1, e=0xbpe=2, PC=001A, disp=CLOOP-PC=0006-001A=-
14=FEC(2’s complement), xbpe+disp=2FEC, obj=3F2FEC
Line 55: LDA=00, n=0, i=1ni=1, op+ni=00+1=01, disp=#3003, x=0,
b=0, p=0, e=0xbpe=0, xbpe+disp=0003, obj=010003

SYSTEM SOFTWARE - UNIT II 48


Program with Object Code (3/2)

SYSTEM SOFTWARE - UNIT II 49


Object Code Translation

Format 2 op(8) r1(4) r2(4)

Line 125: CLEAR=B4, r1=X=1, r2=0, obj=B410


Line 133: LDT=74, n=0, i=1ni=1, op+ni=74+1=75, x=0, b=0,
p=0, e=1xbpe=1, #4096=01000, xbpe+address=101000,
obj=75101000
Line 160: STCH=54, n=1, i=1ni=3, op+ni=54+3=57,
BUFFER=0036, B=0033, disp=BUFFER-B=003, x=1, b=1, p=0,
e=0xbpe=C, xbpe+disp=C003, obj=57C003

SYSTEM SOFTWARE - UNIT II 50


Program with Object Code (3/3)

SYSTEM SOFTWARE - UNIT II 51


SYMTAB
SYMBOL VALUE FLAGS SYMBOL VALUE FLAGS
FIRST 0000 RDREC 1036
CLOOP 0006 RLOOP 1040
ENDFIL 001A EXIT 1056
EOF 002D INPUT 105C
RETADR 0030 WRREC 105D
LENGTH 0033 WLOOP 1062
BUFFER 0036 OUTPUT 1076

SYSTEM SOFTWARE - UNIT II 52


2.2.2 Program Relocation
Example Fig. 2.1
◦ Absolute program, starting address 1000
e.g. 55 101B LDA THREE 00102D
◦ Relocate the program to 2000
e.g. 55 101B LDA THREE 00202D
◦ Each Absolute address should be modified

SYSTEM SOFTWARE - UNIT II 53


2.2.2 Program Relocation
Example Fig. 2.5:
Except for absolute address, the rest of the instructions need not
be modified
not a memory address (immediate addressing)
PC-relative, Base-relative
The only parts of the program that require modification at load
time are those that specify direct addresses

SYSTEM SOFTWARE - UNIT II 54


Example

SYSTEM SOFTWARE - UNIT II 55


Relocatable Program
Modification record
◦ Col 1 M
◦ Col 2-7 Starting location of the address field to be
modified, relative to the beginning of the program
◦ Col 8-9 length of the address field to be modified, in half-
bytes

SYSTEM SOFTWARE - UNIT II 56


Object Code

SYSTEM SOFTWARE - UNIT II 57


Question Bank
1) Mention the different data structures used in two pass assembler along with
brief explanation of their function in both the pass.
2) Generate the object code & object program for the following SIC/XE program.
SUM START 0 Given details of opcode for
instruction
FIRST LDX #0 LDX=04
LDA #0 LDA=00
+LDB #TABLE2 LDB=68
BASE TABLE 2 ADD=18
LOOP ADD TABLE, X TIX=2C
ADD TABLE2, X JLT=38
TIX COUNT STA=0C
JLT LOOP RSUB=4C
+STA TOTAL

RSUB
COUNT RESW 1
TABLE RESW 2000
TABLE RESW 2000

TOTAL RESW 1
END FIRST
SYSTEM SOFTWARE - UNIT II 58
Question Bank
3) Write the fundamental functions of assembler.
4) Generate the object code for each statement & write the object
program for the following SIC/XE program.
WRREC START 105D Given details of opcode
for instruction

CLEAR X CLEAR=B4
LDT LENGTH T=5
WLOOP TD OUTPUT TIX=2C
JEQ WLOOP JLT=38
LDCH BUFFER, X STA=0C
WD OUTPUT RSUB=4C
TI XR T LDT=74
JLT WLOOP TD=E0
RSUB JEQ=30
OUTPUT BYTE X ‘05’ TI XR=B8
BUFFER RESB 400 LDCH=50
LENGTH RESB 2 WD=DC
END WRREC X=1
SYSTEM SOFTWARE - UNIT II 59
Question Bank
5) What is the need of pass 2 assembler? Reason out with simple
example.
6) Define assembler directive. Explain the different types of directives
used in SIC machine.
7) With brief explanation write the algorithm of PASS-1 of two pass
assembler.
8)Briefly explain each & every record format of an object program for
SIC/XE machine.
9) With an example explain OPTAB & SYMTAB.
10) What is program relocation? Explain the problems associated with it
& their solutions.
11)With brief explanation write the algorithm of PASS-2 of two pass
assembler.

SYSTEM SOFTWARE - UNIT II 60


Question Bank
12)Generate the object code for the following SIC program.

SUM START 4000 Given details of opcode


for instruction

FIRST LDX ZERO LDX=04


LDA ZERO LDA=00
LOOP ADD TABLE, X TIX=2C
TIX COUNT STA=0C
JLT LOOP RSUB=4C
STA TOTAL ADD=18
RSUB JLT=38
COUNT RESW 1

TABLE RESW 2000

TABLE RESW 2000


ZERO WORD 0

TOTAL RESW 1
END FIRST

SYSTEM SOFTWARE - UNIT II 61


THANK YOU

SYSTEM SOFTWARE - UNIT II 62

Vous aimerez peut-être aussi