Download presentation
Presentation is loading. Please wait.
1
SYSTEM SOFTWARE - UNIT II
Subject Name: SYSTEM SOFTWARE Subject Code: 10CS52 Prepared By: Suganthi Sivakumar Department: CSE Date SYSTEM SOFTWARE - UNIT II
2
SYSTEM SOFTWARE - UNIT II
Engineered for Tomorrow SYSTEM SOFTWARE - UNIT II
3
SYSTEM SOFTWARE - UNIT II
ASSEMBLERS - I Engineered for Tomorrow SYSTEM SOFTWARE - UNIT II
4
SYSTEM SOFTWARE - UNIT II
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
5
SYSTEM SOFTWARE - UNIT II
Role of Assembler Linker Source Program Assembler Object Code Executable Code Loader SYSTEM SOFTWARE - UNIT II
6
SYSTEM SOFTWARE - UNIT II
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
7
SYSTEM SOFTWARE - UNIT II
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
8
Example of a SIC Assembler Language Program (3/1)
SYSTEM SOFTWARE - UNIT II
9
Example of a SIC Assembler Language Program (3/2)
SYSTEM SOFTWARE - UNIT II
10
Example of a SIC Assembler Language Program (3/3)
SYSTEM SOFTWARE - UNIT II
11
SYSTEM SOFTWARE - UNIT II
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
12
SYSTEM SOFTWARE - UNIT II
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
13
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
14
SYSTEM SOFTWARE - UNIT II
Assembly Program with Object Code Forward reference SYSTEM SOFTWARE - UNIT II
15
SYSTEM SOFTWARE - UNIT II
Assembly Program with Object Code SYSTEM SOFTWARE - UNIT II
16
SYSTEM SOFTWARE - UNIT II
Assembly Program with Object Code SYSTEM SOFTWARE - UNIT II
17
SYSTEM SOFTWARE - UNIT II
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
18
SYSTEM SOFTWARE - UNIT II
Example FIRST STL RETADR X 141033 STCH BUFFER,X 549039 SYSTEM SOFTWARE - UNIT II
19
SYSTEM SOFTWARE - UNIT II
Object Program Format Header Col H Col. 2~7 Program name Col. 8~13 Starting address of object program (hex) Col Length of object program in bytes (hex) Text Col 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 E Col.2~7 Address of first executable instruction in object program (hex) SYSTEM SOFTWARE - UNIT II
20
SYSTEM SOFTWARE - UNIT II
Fig. 2.3 H COPY A T E T 00101E 15 0C C F T E E0205D 30203F D8205D … T C C0000 F E … T C E SYSTEM SOFTWARE - UNIT II
21
Example of Instruction Assemble
STCH BUFFER,X 549039 Forward reference (54) (001) (039)16 SYSTEM SOFTWARE - UNIT II
22
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 … … … … … J CLOOP 1033 RETADR RESW 1 SYSTEM SOFTWARE - UNIT II
23
SYSTEM SOFTWARE - UNIT II
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
24
SYSTEM SOFTWARE - UNIT II
Two Pass Assembler Read from input line LABEL, OPCODE, OPERAND Source program Intermediate file Pass 1 Pass 2 Object codes OPTAB SYMTAB SYMTAB SYSTEM SOFTWARE - UNIT II
25
2.1.2 Assembler Algorithm and Data Structures
Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter(LOCCTR) SYSTEM SOFTWARE - UNIT II
26
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
27
SYSTEM SOFTWARE - UNIT II
SYMTAB (symbol table) Content label name, value, flag, (type, length) etc. Characteristic dynamic table (insert, delete, search) Implementation hash table, non-random keys, hashing function COPY 1000 FIRST CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039 SYSTEM SOFTWARE - UNIT II
28
SYSTEM SOFTWARE - UNIT II
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
29
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 1 SYSTEM SOFTWARE - UNIT II
30
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 1 SYSTEM SOFTWARE - UNIT II
31
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 1 SYSTEM SOFTWARE - UNIT II
32
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 2 SYSTEM SOFTWARE - UNIT II
33
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 2 SYSTEM SOFTWARE - UNIT II
34
SYSTEM SOFTWARE - UNIT II
Pseudo Code for Pass 2 SYSTEM SOFTWARE - UNIT II
35
Machine-dependent Assembler Features
Instruction formats and addressing modes Program relocation SYSTEM SOFTWARE - UNIT II
36
2.2.1 Instruction Format and Addressing Mode
SIC/XE PC-relative or Base-relative addressing: op m Indirect addressing: 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
37
SYSTEM SOFTWARE - UNIT II
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
38
SYSTEM SOFTWARE - UNIT II
PC-Relative Addressing Modes PC-relative FIRST STL RETADR 17202D (14) (02D) 16 displacement= RETADR - PC = 30-3 = 2D J CLOOP 3F2FEC (3C) (FEC) 16 displacement= CLOOP-PC= 6 - 1A= -14= FEC SYSTEM SOFTWARE - UNIT II
39
SYSTEM SOFTWARE - UNIT II
BASE RELATIVE ADDRESSING MODE Base-relative base register is under the control of the programmer 12 LDB #LENGTH 13 BASE LENGTH E STCH BUFFER, X 57C003 ( 54 ) ( 003 ) 16 (54) = -101B16 displacement= BUFFER - B = = 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
40
Immediate Address Translation
Immediate addressing LDA # ( 00 ) ( 003 ) 16 C LDT # ( 74 ) ( ) 16 SYSTEM SOFTWARE - UNIT II
41
Immediate Address Translation(Cont.)
Immediate addressing LDB #LENGTH 69202D ( 68) ( 02D ) 16 ( 68) ( 033) the immediate operand is the symbol LENGTH the address of this symbol LENGTH is loaded into register B LENGTH=0033=PC+displacement= D if immediate mode is specified, the target address becomes the operand SYSTEM SOFTWARE - UNIT II
42
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 3E2003 ( 3C ) ( 003 ) 16 TA=RETADR=0030 TA=(PC)+disp=002D+0003 SYSTEM SOFTWARE - UNIT II
43
Example of SIC/XE Program(3/1)
SYSTEM SOFTWARE - UNIT II
44
Example of SIC/XE Program(3/2)
SYSTEM SOFTWARE - UNIT II
45
Example of SIC/XE Program(3/3)
SYSTEM SOFTWARE - UNIT II
46
Program with Object Code (3/1)
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 x b p e address(20) Line 10: STL=14, n=1, i=1ni=3, op+ni=14+3=17, RETADR=0030, x=0, b=0, p=1, e=0xbpe=2, PC=0003, disp=RETADR-PC= =02D, xbpe+disp=202D, obj=17202D Line 12: LDB=68, n=0, i=1ni=1, op+ni=68+1=69, LENGTH=0033, x=0, b=0, p=1, e=0xbpe=2, PC=0006, disp=LENGTH-PC= =02D, xbpe+disp=202D, obj=69202D SYSTEM SOFTWARE - UNIT II
48
Object Code Translation
Format 3 op(6) n i x b p e disp(12) Format 4 op(6) n i x b p e address(20) Line 15: JSUB=48, n=1, i=1ni=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=1ni=3, op+ni=3C+3=3F, CLOOP=0006, x=0, b=0, p=1, e=0xbpe=2, PC=001A, disp=CLOOP-PC= A=- 14=FEC(2’s complement), xbpe+disp=2FEC, obj=3F2FEC Line 55: LDA=00, n=0, i=1ni=1, op+ni=00+1=01, disp=#3003, x=0, b=0, p=0, e=0xbpe=0, xbpe+disp=0003, obj=010003 SYSTEM SOFTWARE - UNIT II
49
Program with Object Code (3/2)
SYSTEM SOFTWARE - UNIT II
50
Object Code Translation
Line 125: CLEAR=B4, r1=X=1, r2=0, obj=B410 Line 133: LDT=74, n=0, i=1ni=1, op+ni=74+1=75, x=0, b=0, p=0, e=1xbpe=1, #4096=01000, xbpe+address=101000, obj= Line 160: STCH=54, n=1, i=1ni=3, op+ni=54+3=57, BUFFER=0036, B=0033, disp=BUFFER-B=003, x=1, b=1, p=0, e=0xbpe=C, xbpe+disp=C003, obj=57C003 Format 2 op(8) r1(4) r2(4) SYSTEM SOFTWARE - UNIT II
51
Program with Object Code (3/3)
SYSTEM SOFTWARE - UNIT II
52
SYSTEM SOFTWARE - UNIT II
SYMTAB SYMBOL VALUE FLAGS FIRST 0000 CLOOP 0006 ENDFIL 001A EOF 002D RETADR 0030 LENGTH 0033 BUFFER 0036 SYMBOL VALUE FLAGS RDREC 1036 RLOOP 1040 EXIT 1056 INPUT 105C WRREC 105D WLOOP 1062 OUTPUT 1076 SYSTEM SOFTWARE - UNIT II
53
SYSTEM SOFTWARE - UNIT II
2.2.2 Program Relocation Example Fig. 2.1 Absolute program, starting address 1000 e.g B LDA THREE D Relocate the program to 2000 e.g B LDA THREE D Each Absolute address should be modified SYSTEM SOFTWARE - UNIT II
54
SYSTEM SOFTWARE - UNIT II
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
55
SYSTEM SOFTWARE - UNIT II
Example SYSTEM SOFTWARE - UNIT II
56
SYSTEM SOFTWARE - UNIT II
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 length of the address field to be modified, in half- bytes SYSTEM SOFTWARE - UNIT II
57
SYSTEM SOFTWARE - UNIT II
Object Code SYSTEM SOFTWARE - UNIT II
58
SYSTEM SOFTWARE - UNIT II
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 Given details of opcode for instruction FIRST LDX #0 LDX=04 LDA LDA=00 +LDB #TABLE2 LDB=68 BASE TABLE 2 ADD=18 LOOP ADD TABLE, X TIX=2C TABLE2, X JLT=38 TIX COUNT STA=0C JLT RSUB=4C +STA TOTAL RSUB RESW 1 TABLE 2000 END SYSTEM SOFTWARE - UNIT II
59
SYSTEM SOFTWARE - UNIT II
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 JLT=38 LDCH BUFFER, X STA=0C WD RSUB=4C TI XR T LDT=74 JLT TD=E0 RSUB JEQ=30 BYTE X ‘05’ TI XR=B8 BUFFER RESB 400 LDCH=50 2 WD=DC END X=1 SYSTEM SOFTWARE - UNIT II
60
SYSTEM SOFTWARE - UNIT II
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
61
SYSTEM SOFTWARE - UNIT II
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 LDA=00 LOOP ADD TABLE, X TIX=2C TIX COUNT STA=0C JLT RSUB=4C STA TOTAL ADD=18 RSUB JLT=38 RESW 1 TABLE 2000 WORD END SYSTEM SOFTWARE - UNIT II
62
SYSTEM SOFTWARE - UNIT II
THANK YOU SYSTEM SOFTWARE - UNIT II
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.