ss unit-iiassembler 2007
TRANSCRIPT
-
8/12/2019 Ss Unit-iiassembler 2007
1/122
1MC9224 System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
2/122
2MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
OutlineBasic Assembler FunctionsA simpler SIC AssemblerAssembler Algorithm and Data Structures
Machine-Dependent Assembler FeaturesInstruction Formats and Addressing Modes
Program LocationMachine-Independent Assembler Features
LiteralsSymbol-Defining StatementsExpressionsProgram Blocks
Control Section and Program LinkingAssembler Design Options
One-Pass AssemblerMulti-Pass Assembler
Implementation ExamplesMASM Assembler
-
8/12/2019 Ss Unit-iiassembler 2007
3/122
3MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1. Basic Assembler FunctionsExample Program SIC AssemblerPurpose
Reads records from input device (code F1) and store in BUFFER
Copies them to output device (code 05) At the end of the file, writes an extra EOF on the output device,then RSUB to the operating system
Data transfer (RD, WD)End of each record is marked with a null characterEnd of the file is indicated by a zero-length record
Subroutines (JSUB, RSUB)RDREC, WRRECSave link register first before nested jump
-
8/12/2019 Ss Unit-iiassembler 2007
4/122
4MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1. Basic Assembler Functions
5 COPY START 1000 LOAD PROG AT LOC 100010 FIRST STL RETADR SAVE RETURN ADDRESS15 CLOOP JSUB RDREC READ INPUT RECORD20 LDA LENGTH TEST FOR EOF (LENGTH = 0)25 COMP ZERO30 JEQ ENDFIL EXIT IF EOF FOUND35 JSUB WRREC WRITE OUTPUT RECORD40 J CLOOP LOOP45 ENDFIL LDA EOF INSERT END OF FILE MARKER50 STA BUFFER55 LDA THREE SET LENGTH = 360 STA LENGTH65 JSUB WRREC WRITE EOF70 LDL RETADR GET RETURN ADDRESS
75 RSUB RETURN TO CALLER80 EOF BYTE CEOF 85 THREE WORD 390 ZERO WORD 095 RETADR RESW 1100 LENGTH RESW 1105 BUFFER RESB 4096 4096-BYTE BUFFER AREA
-
8/12/2019 Ss Unit-iiassembler 2007
5/122
5MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1. Basic Assembler Functions110 .115 . SUBROUTINE TO READ RECORD INTO BUFFER120 .125 RDREC LDX ZERO CLEAR LOOP COUNTER130 LDA ZERO CLEAR A TO ZERO
135 RLOOP TD INPUT TEST INPUT DEVICE140 JEQ RLOOP LOOP UNTIL READY145 RD INPUT READ CHARACTER INTO A150 COMP ZERO TEST FOR END OF RECORD155 JEQ EXIT EXIT LOOP IF EOR160 STCH BUFFER,X STORE CHAR IN BUFFER165 TIX MAXLEN LOOP UNLESS MAX LENGTH170 JLT RLOOP HAS BEEN REACHED175 EXIT STX LENGTH SAVE RECORD LENGTH180 RSUB RETURN TO CALLER185 INPUT BYTE XF1 CODE FOR INPUT DEVICE190 MAXLEN WORD 4096
-
8/12/2019 Ss Unit-iiassembler 2007
6/122
6MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1. Basic Assembler Functions195 .200 . SUBROUTINE TO WRITE RECORD FROM BUFFER205 .210 WRREC LDX ZERO CLEAR LOOP COUNTER215 WLOOP TD OUTPUT TEST OUTPUT DEVICE220 JEQ WLOOP LOOP UNTIL READY225 LDCH BUFFER,X GET CHAR FROM BUFFER230 WD OUTPUT WRITE CHARACTER235 TIX LENGTH LOOP UNTIL ALL CHAR
240 JLT WLOOP HAVE BEEN WRITTEN245 RSUB RETURN TO CALLER250 OUTPUT BYTE X05 CODE FOR OUTPUT DEVICE255 END FIRST
-
8/12/2019 Ss Unit-iiassembler 2007
7/1227MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1. Basic Assembler Functions
Assembler DirectivesPseudo-Instructions / Basic assembler directives
Not translated into machine instructions
Providing information to the assemblerBasic assembler directives
START Specifies starting memory address of object programEND Marks the end of the program
BYTE Generate Character / Hexadecimal constant 1 byteWORD Generate 1 word constantRESB Reserve the indicated number of bytes for data areaRESW Reserve the indicated number of words for data area
-
8/12/2019 Ss Unit-iiassembler 2007
8/1228MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler
Mnemonic code (or instruction name) opcodeSymbolic operands (e.g., variable names) MachineaddressesChoose the proper instruction format and addressingmodeConstants Equivalent Internal Machine representationOutput to object files and listing files
-
8/12/2019 Ss Unit-iiassembler 2007
9/1229MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Example Program &Object Code
Line Loc Source statement Object code5 1000 COPY START 100010 1000 FIRST STL RETADR 14103315 1003 CLOOP JSUB RDREC 482039
20 1006 LDA LENGTH 00103625 1009 COMP ZERO 28103030 100C JEQ ENDFIL 30101535 100F JSUB WRREC 48206140 1012 J CLOOP 3C100345 1015 ENDFIL LDA EOF 00102A50 1018 STA BUFFER 0C103955 101B LDA THREE 00102D60 101E STA LENGTH 0C103665 1021 JSUB WRREC 48206170 1024 LDL RETADR 08103375 1027 RSUB 4C0000
-
8/12/2019 Ss Unit-iiassembler 2007
10/12210MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Example Program &Object Code
Line Loc Source statement Object code
80 102A EOF BYTE CEOF 454F4685 102D THREE WORD 3 00000390 1030 ZERO WORD 0 00000095 1033 RETADR RESW 1100 1036 LENGTH RESW 1105 1039 BUFFER RESB 4096
-
8/12/2019 Ss Unit-iiassembler 2007
11/12211MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Example Program &Object Code
110 . 115 . SUB TO READ RECORD INTO BUFFER120 . 125 2039 RDREC LDX ZERO 041030
130 203C LDA ZERO 001030135 203F RLOOP TD INPUT E0205D140 2042 JEQ RLOOP 30203F145 2045 RD INPUT D8205D150 2048 COMP ZERO 281030155 204B JEQ EXIT 302057160 204E STCH BUFFER,X 549039165 2051 TIX MAXLEN 2C205E170 2054 JLT RLOOP 38203F175 2057 EXIT STX LENGTH 101036180 205A RSUB 4C0000185 205D INPUT BYTE XF1 F1190 205E MAXLEN WORD 4096 001000
-
8/12/2019 Ss Unit-iiassembler 2007
12/12212MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Example Program &Object Code
195 .200 . SUB TO WRITE RECORD FROM BUFFER205 .
210 2061 WRREC LDX ZERO 041030215 2064 WLOOP TD OUTPUT E02079220 2067 JEQ WLOOP 302064225 206A LDCH BUFFER,X 509039230 206D WD OUTPUT DC2079235 2070 TIX LENGTH 2C1036240 2073 JLT WLOOP 382064245 2076 RSUB 4C0000250 2079 OUTPUT BYTE X05 05255 END FIRST
-
8/12/2019 Ss Unit-iiassembler 2007
13/12213MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Mnemonic code (or instruction name) opcodeExamples:STL 1033 14 10 33
LDA 1036 00 10 36
0001 0100 0 001 0000 0011 0011
0000 0000 0 001 0000 0011 0110
-
8/12/2019 Ss Unit-iiassembler 2007
14/12214MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Converting Symbolto Numbers
Isn t it straightforward?Isn t it simply the sequential processing of the sourceprogram, one line at a time?
Not so, if we have forward references we don t know the value of the symbol, because it isdefined later in the code Need two pass Assembler
Loc Label Operator Operand1000 FIRST STL RETADR
1003 CLOOP JSUB RDREC
1012 J CLOOP 1033 RETADR RESW 1
-
8/12/2019 Ss Unit-iiassembler 2007
15/122
15MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Symbolic Operands
We are not likely to write memory addressesdirectly in our code
Instead, we will define variable names
Other examples of symbolic operands:Labels (for jump instructions)Subroutines
Constants
-
8/12/2019 Ss Unit-iiassembler 2007
16/122
16MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Two Pass AssemblerPass1
Scan the source programIdentify the label definitions and assign addresses
Pass2 All other assembler operations
Load and Execution
-
8/12/2019 Ss Unit-iiassembler 2007
17/122
-
8/12/2019 Ss Unit-iiassembler 2007
18/122
18MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler Object Program
H^ COPY ^ 001000 ^ 00107AT^ 001000 ^ 1E^ 141033 ^ 482039 ^ 001036 ^ 281030 ^ 301015 ^ 482061 ^ 3C1003 ^ 00102A ^ 0C1039 ^ 00102DT^ 00101E ^ 15 ^ 0C1036 ^ 482061 ^ 081044 ^ 4C0000 ^ 454F46 ^ 000003 ^ 000000T^ 002039 ^ 1E^ 041030 ^ 001030 ^ E0205D ^ 30203F ^ D8205D ^ 281030 ^ 302057 ^ 549039 ^ 2C205E ^ 38203FT^ 002057 ^ 1C^ 101036 ^ 4C0000 ^ F1^ 001000 ^ 041030 ^ E02079 ^ 302064 ^ 509039 ^ DC2079 ^ 2C1036T^ 002073 ^ 07 ^ 382064 ^ 4C0000 ^ 05E^ 001000 starting address
-
8/12/2019 Ss Unit-iiassembler 2007
19/122
19MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.1. A Simple SIC Assembler
Pass 1 Assign addresses to all statements in the program
Save the values assigned to all labels for use in Pass 2Perform some processing of assembler directives
Pass 2 Assemble instructions by translating opcode and symbolicoperandsGenerate data values defined by BYTE, WORDPerform processing of assembler directives not done in Pass 1Write the object program and the assembly listing
Functions of a Two Pass Assembler
-
8/12/2019 Ss Unit-iiassembler 2007
20/122
20MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures
Internal Data Structures Two Major Data structures
Operation Code Table (OPTAB)
Symbol Table (SYMTAB)One variable - Location Counter (LOCCTR)
Pass 1 Pass 2Intermediatefile
OPTAB SYMTAB SYMTAB
Sourceprogram
Objectcode
-
8/12/2019 Ss Unit-iiassembler 2007
21/122
21MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures OPTAB (Operation Code Table)
ContentMnemonic names, machine code (instruction format, length forSIC/XE) etc.
CharacteristicStatic table (assembler itself written)Implementation
Array or hash table(mnemonic operation code as key), easy forsearch
UsagePass 1 - look up and validate mnemonic operation codes in thesource programPass 2 translate opcodes into machine language
-
8/12/2019 Ss Unit-iiassembler 2007
22/122
22MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures SYMTAB (Symbol Table)
ContentLabel name, value, flag, (type, length for dataarea ) etc.
CharacteristicDynamic table (insert, delete, search)
ImplementationHash table, non-random keys, hashingfunction
UsagePass 1 - enter symbol names into SYMTABalong with the assign address ( from LOCCTR)Pass 2 look up symbols, fetch address andinsert in object code
COPY 1000FIRST 1000CLOOP 1003
ENDFIL 1015EOF 1024THREE 102DZERO 1030RETADR 1033LENGTH 1036BUFFER 1039RDREC 2039
-
8/12/2019 Ss Unit-iiassembler 2007
23/122
23MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures Intermediate File
Pass1 and pass2 use source program as input.Other information should be passed between twopasses.Pass 1 writes an intermediate file
Each source statement together with its assigned addressError indicatorsUsed as input for pass 2
-
8/12/2019 Ss Unit-iiassembler 2007
24/122
24MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler
-
8/12/2019 Ss Unit-iiassembler 2007
25/122
25MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler
O S k hi
-
8/12/2019 Ss Unit-iiassembler 2007
26/122
26MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler
O S k hi
-
8/12/2019 Ss Unit-iiassembler 2007
27/122
27MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler
-
8/12/2019 Ss Unit-iiassembler 2007
28/122
O S kthi
-
8/12/2019 Ss Unit-iiassembler 2007
29/122
29MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2. Machine-Dependent Assembler Features SIC/XE Assembler
We have learned the 2-pass assembler for SICWhats new for SIC/XE?
More addressing modesProgram relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
30/122
30MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes
SIC/XE:PC-relative or base-relative addressing: op mIndirect addressing: op @mImmediate addressing: op #cExtended format: +op mIndex addressing: op m,xRegister-to-register instructionsLarger memory multi-programming (programallocation)
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
31/122
31MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing ModesRegister translation during pass 2
Register name (A, X, L, B, S, T, F, PC, SW) translated totheir ids (0,1, 2, 3, 4, 5, 6, 8, 9)Use separate table or may be preloaded in SYMTAB
Address translationRegister-memory instructions: try PC-relative first, thenbase-relative addressing
Assembler makes its own decisionUser must specify extended format (format 4), otherwise errorwill be generated by the assembler
Format 3: 12-bit displacementBase-relative: 0~4095 PC-relative: -2048~2047
Format 4: 20-bit address field
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
32/122
32MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing ModesLine Loc Source statement Object code 5 0000 COPY START 010 0000 FIRST STL RETADR 17202D12 0003 LDB #LENGTH 69202D13 BASE LENGTH15 0006 CLOOP +JSUB RDREC 4B10103620 000A LDA LENGTH 03202625 000D COMP #0 29000030 0010 JEQ ENDFIL 33200735 0013 +JSUB WRREC 4B10105D40 0017 J CLOOP 3F2FEC45 001A ENDFIL LDA EOF 03201050 001D STA BUFFER 0F201655 0020 LDA #3 010003
60 0023 STA LENGTH 0F200D65 0026 +JSUB WRREC 4B10105D70 002A J @RETADR 3E200380 002D EOF BYTE CEOF 454F4695 0030 RETADR RESW 1100 0033 LENGTH RESW 1105 0036 BUFFER RESB 4096
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
33/122
33MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes115 . READ RECORD INTO BUFFER120 .125 1036 RDREC CLEAR X B410130 1038 CLEAR A B400132 103A CLEAR S B440
133 103C +LDT #4096 75101000135 1040 RLOOP TD INPUT E32019140 1043 JEQ RLOOP 332FFA145 1046 RD INPUT DB2013150 1049 COMPR A, S A004155 104B JEQ EXIT 332008160 104E STCH BUFFER,X 57C003165 1051 TIXR T B850170 1053 JLT RLOOP 3B2FEA175 1056 EXIT STX LENGTH 134000180 1059 RSUB 4F0000185 105C INPUT BYTE XF1 F1
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
34/122
34MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes195 .200 . WRITE RECORD FROM BUFFER205 .210 105D WRREC CLEAR X B41012 105F LDT LENGTH 774000215 1062 WLOOP TD OUTPUT E32011220 1065 JEQ WLOOP 332FFA225 1068 LDCH BUFFER,X 53C003230 106B WD OUTPUT DF2008235 106E TIXR T B850240 1070 JLT WLOOP 3B2FEF245 1073 RSUB 4F0000250 1076 OUTPUT BYTE X05 05255 END FIRST
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
35/122
35MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes
10 0000 FIRST STL RETADR 17202D
Displacement= RETADR PC = 0030 0003 = 02D
40 0017 J CLOOP 3F2FEC
Displacement= CLOOP PC= 0006 001A= 14= FEC
OPCODE e Addressn i x b p
0001 01 0 (02D) 16 1 1 0 0 1
OPCODE e Addressn i x b p
0011 11 0 (FEC) 16 1 1 0 0 1
PC Relative Addressing
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
36/122
36MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes Base Relative Addressing Mode
BASE register and directive:12 LDB #LENGTH13 BASE LENGTH
Base register is under the control of programmerBASE directive tells assembler that LENGHTH is base address;NOBASE releases the binding, until B value will be used as Baseaddress
160 104E STCH BUFFER, X 57C003
Displacement= BUFFER B = 0036 0033 = 3Compare lines 20 and 175 (PC vs Base addressing)
OPCODE e Addressn i x b p
0101 01 0 (003) 16 1 1 1 1 0
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
37/122
37MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes Base Relative Addressing Mode
Why cannot we use PC-relative?
Assembler knows the PC value at execution time, it cannotbe changeableBase register is under the control of programmer, and setinitially and changeable
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
38/122
38MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur-603 319
55 0020 LDA #3 010003
133 103C +LDT #4096 75101000
OPCODE e Addressn i x b p
0000 00 0 (003) 16 0 1 0 0 0
OPCODE e Addressn i x b p
0111 01 1 (01000) 16 0 1 0 0 0
2.2.1. Instruction Formats and Addressing Modes Immediate Address Translation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
39/122
39MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.2.1. Instruction Formats and Addressing ModesImmediate Address Translation
12 0003 LDB #LENGTH 69202D
12 0003 LDB #LENGTH 690033
The immediate operand is the value of the symbol LENGTH, which isthe address assigned to LENGTHLENGTH=0033=PC+displacement=0006+02D
OPCODE e Addressn i x b p
0110 10 0 (02D) 16 0 1 0 0 1
OPCODE e Addressn i x b p
0110 10 0 (033) 16 0 1 0 0 0
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
40/122
40MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.2.1. Instruction Formats and Addressing Modes Indirect Address Translation
Target addressing is computed as usual (PC-relativeor BASE-relative)Only the n bit is set to 1
70 002A J @RETADR 3E2003
TA=RETADR=0030TA=(PC)+displacement=002D+0003
OPCODE e Addressn i x b p
0011 11 0 (003) 16 1 0 0 0 1
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
41/122
41MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.2.2. Program Relocation
Need for program relocationExample :
If program starts at 1000
55 101B LDA THREE 00102DIf program starts at 2000
55 201B LDA THREE 00202DSome lines need not be modified (line 85, value 3)
Assembler does not know that where the program willbe loaded, but it can inform to loader via modificationrecords.
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
42/122
42MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Loaded at 0000 Loaded at 5000 Loaded at 7420
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
43/122
43MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Example Fig. 2.2 Absolute program , starting address 1000
5 2000 1000 COPY START 100010 2000 1000 FIRST STL RETADR 141033 14203315 2003 1003 CLOOP JSUB RDREC 482039 48303920 2006 1006 LDA LENGTH 001036 00203625 2009 1009 COMP ZERO 281030 28203030 200C 100C JEQ ENDFIL 301015 30201535 200F 100F JSUB WREC 482061 48306140 2012 1012 J CLOOP 3C1003 3C200345 2015 1015 ENDFIL LDA EOF 00102A 00202A50 2018 1018 STA BUFFER 0C1039 0C203955 201B 101B LDA THREE 00102D 00202D60 201E 101E STA LENGTH 0C1036 0C203665 2021 1021 JSUB WREC 482061 483061
70 2024 1024 LDL RETADR 081033 08203375 2027 1027 RSUB 4C0000 4C000080 202A 102A EOF BYTE C'EOF' 454E46 454E4685 202D 102D THREE WORD 3 000003 00000390 2030 1030 ZERO WORD 0 000000 00000095 2033 1033 RETADR RESW 1100 2036 1036 LENGTH RESW 1105 2039 1039 BUFFER RESB 4096
==== 2000==== 2000
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
44/122
44MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Example Fig. 2.6:Except for absolute address, rest of the instructions need not be modifiednot a memory address (immediate addressing)PC-relative, Base-relative
Parts requiring modification at load time are those with absolute addresses
== 10005 1000 0000 COPY START 010 1000 0000 FIRST STL RETADR 17202D 17202D12 1003 0003 LDB #LENGTH 69202D 69202D13 BASE LENGTH15 1006 0006 CLOOP +JSUB RDREC 4B101036 4B10 203620 100A 000A LDA LENGTH 032026 03202625 100D 000D COMP #0 290000 29000030 1010 0010 JEQ ENDFIL 332007 33200735 1013 0013 +JSUB WRREC 4B10105D 4B10 205D40 1017 0017 J CLOOP 3F2FEC 3F2FEC45 101A 001A ENDFIL LDA EOF 032010 032010
50 101D 001D STA BUFFER 0F2016 0F201655 1020 0020 LDA #3 010003 01000360 1023 0023 STA LENGTH 0F200D 0F200D65 1026 0026 +JSUB WRREC 4B10105D 4B10 205D70 102A 002A J @RETADR 3E2003 3E200380 102D 002D EOF BYTE C'EOF' 454F46 454F4695 1030 0030 RETADR RESW 1100 1036 0036 BUFFER RESB 4096
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
45/122
45MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Use relative addressesDid you notice that we didn t modify the addresses for JEQ, JLTand J instructions?
We didn t modify the addresses for RETADR, LENGTH, andBUFFER in Figure 2.6 either.
The sample SIC/EX program is easierMostly PC or base relative
Only extended format instructions have direct addresses andrequire modification
Making Program Relocation Easier
2.2.2. Program Relocation
-
8/12/2019 Ss Unit-iiassembler 2007
46/122
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
47/122
47MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Modification records are added to the object files.(See pp.67 and Figure 2.8.)Example:
HCOPY 001000 001077T000000 1D 17202D4B101036 T00001D
M000007 05 Modification Record E000000
Object File with M-Records
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
48/122
48MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Modification Record
0009 3 61 0
1 04 B2 D
0008
000700060005
+JSUB RDREC
0004 2 06 92 D2 01 7
0003000200010000
LDB #LENGTH
STL RETADR
000C 2 62 00 3
000B000A LDA LENGTH
M000007 05
Address 0007
5 half- bytes
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
49/122
49MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Object Code
2.2.2. Program Relocation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
50/122
50MC9224 - System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
Design ideaLet programmers write the value of a constantoperand as a part of the instruction that uses it
Avoids having to define the constant elsewhere inthe program and make up a label for it
Example (Fig. 2.10)045 001A ENDFIL LDA =CEOF 215 1062 WLOOP TD =X 05
2.3. Machine-Independent Assembler Features - Literals
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
51/122
51MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Example Program5 0000 COPY START 010 0000 FIRST STL RETADR 17202D13 0003 LDB #LENGTH 69202D14 BASE LENGTH15 0006 CLOOP +JSUB RDREC 4B10103620 000A LDA LENGTH 03202625 000D COMP #0 29000030 0010 JEQ ENDFIL 33200735 0013 +JSUB WRREC 4B10105D40 0017 J CLOOP 3F2FEC45 001A ENDFIL LDA =CEOF 03201050 001D STA BUFFER 0F201655 0020 LDA #3 01000360 0023 STA LENGTH 0F200D65 0026 +JSUB WRREC 4B10105D
70 002A J @RETADR 3E200393 LTORG95 0030 RETADR RESW 1100 0033 LENGTH RESW 1105 0036 BUFFER RESB 4096106 1036 BUFEND EQU *107 1000 MAXLEN EQU BUFEND - BUFFER
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
52/122
52MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Example Program115 . READ RECORD INTO BUFFER120 .125 1036 RDREC CLEAR X B410130 1038 CLEAR A B400132 103A CLEAR S B440
133 103C +LDT #MAXLEN 75101000135 1040 RLOOP TD INPUT E32019140 1043 JEQ RLOOP 332FFA45 1046 RD INPUT DB2013150 1049 COMPR A,S A004155 104B JEQ EXIT 332008160 104E STCH BUFFER,X 57C003165 1051 TIXR T B850170 1053 JLT RLOOP 3B2FEA175 1056 EXIT STX LENGTH 134000180 1059 RSUB 4F0000185 105C INPUT BYTE XF1 F1
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
53/122
53MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Example Program
195 .200 . WRITE RECORD FROM BUFFER205 .
210 105D WRREC CLEAR X B410212 105F LDT LENGTH 774000215 1062 WLOOP TD =X05 E32011220 1065 JEQ WLOOP 332FFA225 1068 LDCH BUFFER,X 53C003230 106B WD =X05 DF2008
235 106E TIXR T B850240 1070 JLT WLOOP 3B2FEF245 1073 RSUB 4F0000255 END FIRST
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
54/122
54MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.2. Machine-Independent Assembler Features - Literals
Literal vs. Immediate Operands
Immediate operandsOperand value is assembled as part of the machineinstruction
55 0020 LDA #3 010003Literals
The assembler generates the specified value as a constantat some other memory location
45 001A ENDFIL LDA =CEOF 032010Compare (Fig. 2.6)45 001A ENDFIL LDA EOF 03201080 002D EOF BYTE CEOF 454F46
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
55/122
55MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Literal Implementation (1/4)
Literal pools All the literals used in the program grouped together in toone or more literal pools
Normally literals are placed into a pool at the end of theprogram
See Fig. 2.10 (after END statement)
In some cases, it is desirable to place literals into a pool atsome other location in object program
Use assembler directive LTORG: create a literal pool thatcontains all of the literal operands used since the previousLTROG, and place it where LTORG was encounteredReason: keep literal operand close to the instruction
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
56/122
56MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Example Program with Literal Implementation5 0000 COPY START 010 0000 FIRST STL RETADR 17202D13 0003 LDB #LENGTH 69202D14 BASE LENGTH15 0006 CLOOP +JSUB RDREC 4B10103620 000A LDA LENGTH 03202625 000D COMP #0 290000
30 0010 JEQ ENDFIL 33200735 0013 +JSUB WRREC 4B10105D40 0017 J CLOOP 3F2FEC45 001A ENDFIL LDA =CEOF 03201050 001D STA BUFFER 0F201655 0020 LDA #3 01000360 0023 STA LENGTH 0F200D65 0026 +JSUB WRREC 4B10105D70 002A J @RETADR 3E200393 LTORG002D * =CEOF 454F4695 0030 RETADR RESW 1100 0033 LENGTH RESW 1105 0036 BUFFER RESB 4096106 1036 BUFEND EQU *107 1000 MAXLEN EQU BUFEND - BUFFER
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
57/122
57MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
115 . READ RECORD INTO BUFFER120 .125 1036 RDREC CLEAR X B410130 1038 CLEAR A B400
132 103A CLEAR S B440133 103C +LDT #MAXLEN 75101000135 1040 RLOOP TD INPUT E32019140 1043 JEQ RLOOP 332FFA145 1046 RD INPUT DB2013150 1049 COMPR A,S A004155 104B JEQ EXIT 332008160 104E STCH BUFFER,X 57C003165 1051 TIXR T B850170 1053 JLT RLOOP 3B2FEA175 1056 EXIT STX LENGTH 134000180 1059 RSUB 4F0000185 105C INPUT BYTE XF1 F1
Example Program with Literal Implementation
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
58/122
58MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Example Program with Literal Implementation
195 .200 . WRITE RECORD FROM BUFFER205 .210 105D WRREC CLEAR X B410212 105F LDT LENGTH 774000215 1062 WLOOP TD =X05 E32011220 1065 JEQ WLOOP 332FFA225 1068 LDCH BUFFER,X 53C003230 106B WD =X05 DF2008235 106E TIXR T B850240 1070 JLT WLOOP 3B2FEF245 1073 RSUB 4F0000255 END FIRST
1076 * =X05 05
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
59/122
59MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Duplicate literals215 1062 WLOOP TD =X05
230 106B WD =X05 Assembler should recognize duplicate literals andstore only one copy of specified data value
By comparing defining character string, e.g. =X05 By comparing the generated data value, e.g. =CEOF and=X454F46, but benefits are usually not great enough to
justify the additional complexity in the assembler
Literal Implementation (2/4)
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
60/122
60MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Literal Implementation (3/4) Problem of duplicate literalrecognition
'*' denotes a literal refer to the current value oflocation counter.Some have same name, but different values.
BASE *LDB =*
If the literal value represents an 'address' in theprogram, the assembler must also generate theappropriate 'Modification records'
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
61/122
61MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3. Machine-Independent Assembler Features - Literals
Literal Implementation (4/4)
Use LITTAB:Literal name, operand value & length, operand address
Pass 1
Build LITTAB with literal name, operand value/lengthWhen LTORG is encountered, assign address to each literal not yetassigned an address, update LOCCTR
Pass 2Search LITTAB for each literal encountered and generate the
operand addressData values of literals in literal pool are generated similarly as usingBYTE or WORD statementsGenerate modification record for literals that represent an addressin the program
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
62/122
62MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement
Users can define labels on instructions or data areasThe value of a label is the address assigned to the statement
Users can also define symbols with valuessymbol EQU value
value can be constants, other symbols, expressionsMaking source program easier to understandNo forward reference
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
63/122
63MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statementExample 1: replacing symbolic names133 LDT #4096replaced as
MAXLEN EQU 4096133 +LDT #MAXLEN
Example 2: defining mnemonic names for registers A EQU 0
X EQU 1
RMO A,Xcan be replaced as
RMO 0,1
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
64/122
64MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statementExample 3: defining registers with symbolic namesv(SIC)
BASE EQU R1COUNT EQU R2INDEX EQU R3
To represent registers 1,2,3
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
65/122
65MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement Assembler directive ORG
Allow the assembler to reset the PC to values. ORG values
Use to indirectly assign values to symbols When ORG is encountered, the assembler resets its
LOCCTR to the specified value ORG will affect the values of all labels defined until the
next ORG. If the previous value of LOCCTR can be automaticallyremembered, we can return to the normal use ofLOCCTR by simply write ORG
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
66/122
66MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement
In the data structureSymbol :6 bytes
Value :3 bytesFlags :2 bytes
If EQU statements are used
STAB RESB 1100SYMBOL EQU STAB VALUE EQU STAB+6FLAG EQU STAB+9
Symbol table structure to support ORG
Symbol Value Flags
STAB
(100 entries)
: : :
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
67/122
67MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement
If ORG statements are usedSTAB RESB 1100
ORG STAB Set LOCCTR to STAB
SYMBOL RESB 6 VALUE RESW 1 Size of each fieldFLAGS RESB 2
ORG STAB +1100 Restore LOCCTR
VALUE field fetched byLDA VALUE,X
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
68/122
68MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement
All symbols used in the right hand side must be definedpreviously in the program
ALPHA RESW 1BETA EQU ALPHA
BETA EQU ALPHA ALPHA RESW 1
ALPHA EQU BETABETA EQU DELTADELTA RESW 1
Restriction with EQU
Valid
Invalid
Invalid
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
69/122
69MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.2. Machine-Independent Assembler Features Symbol Defining
statement
All symbols used to specify the new location countervalue must have been previously defined
ORG ALPHABYTE1 RESB 1BYTE2 RESB 2
BYTE3 RESB 3ORG ALPHA RESB 1
Restriction with ORG
Invalid
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
70/122
70MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.3. Machine-Independent Assembler Features Expressions
Assemblers allow the use of expressions as operand The assembler calculates the expressions and produce a single
operand address or value. Operator +,-,*,/
Division is usually defined to produce an integer result Expressions may be constants, user-defined symbols or specialterms.
106 1036 BUFFEND EQU * Gives BUFFEND a value that is the address of the next byte after
the buffer area Examples MAXLEN EQU BUFEND-BUFFER STAB RESB (6+3+2)*MAXENTRIES
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
71/122
71MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.3. Machine-Independent Assembler Features Expressions
Values of terms can be Absolute (independent of program location)
Constants
Relative (to the beginning of the program) Address labels * (value of LOCCTR)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
72/122
72MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.3. Machine-Independent Assembler Features Expressions
Expressions can be Absolute
Only absolute termsRelative terms in pairs with opposite signs for each pair.
Relative All the relative terms except one can be paired as described in absolute .The remaining unpaired relative term must have a positivesign.No relative terms may enter into a multiplication or divisionoperation
Expressions that do not meet the conditions of either absolute or relative should be flagged as errors.
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
73/122
73MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.3. Machine-Independent Assembler Features Expressions
Assembler needs to track type of anexpression, to generate Modificationrecords if neededNeed a flag in the SYMTAB for
indication Absolute value
BUFFEND BUFFER
Illegal
BUFFEND + BUFFER100 BUFFER3* BUFFER
Handling relative terms in SYMTAB
Symbol Type Flag
RETADR R 0030
BUFFER R 0036BUFEND R 1036
MAXLEN A 1000
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
74/122
74MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Allow the generated machine instructions and data toappear in the object program in a different order
Gather all code segments, data segments and stack segments
Program blocks vs. Control sectionsProgram blocks
Segments of code that are rearranged within a single objectprogram unit
Control sectionSegments of code that are translated into independent objectprogram units
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
75/122
75MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Assembler directive : USEUSE [blockname]
At the beginning, statements are assumed to be part of the unnamed(default) block If no USE statements are included, the entire program belongs to this
single block Each program block may actually contain several separate segments ofthe source program
Assembler rearrange these segments to gather together the pieces ofeach block and assign address
Separate the program into blocks in a particular orderLarge buffer area is moved to the end of the object programProgram readability is better if data areas are placed in the sourceprogram close to the statements that reference them
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
76/122
76MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Three blocks are useddefault: executable instructionsCDATA: all data areas that are less in length
CBLKS: all data areas that consists of largerblocks of memory
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
77/122
77MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Line Source statement Object Code 5 0000 0 COPY START 010 0000 0 FIRST STL RETADR 17202D15 0003 0 CLOOP JSUB RDREC 4B202120 0006 0 LDA LENGTH 03202625 0009 0 COMP #0 29000030 000C 0 JEQ ENDFIL 33200635 000F 0 JSUB WRREC 4B203B40 0012 0 J CLOOP 3F2FEE45 0015 0 ENDFIL LDA =CEOF 03205550 0018 0 STA BUFFER 0F205655 001B 0 LDA #3 01000360 001E 0 STA LENGTH 0F204865 0021 0 JSUB WRREC 4B202970 0024 0 J @RETADR 3E203F
92 0000 1 USE CDATA95 0000 1 RETADR RESW 1100 0003 1 LENGTH RESW 1103 0000 2 USE CBLKS105 0000 2 BUFFER RESB 4096106 1000 2 BUFEND EQU *107 1000 MAXLEN EQU BUFEND - BUFFER
(Figure 2.11)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
78/122
78MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
115 . READ RECORD INTO BUFFER120 .123 0027 0 USE125 0027 0 RDREC CLEAR X B41030 0029 0 CLEAR A B400132 002B 0 CLEAR S B440133 002D 0 +LDT #MAXLEN 75101000135 0031 0 RLOOP TD INPUT E32038140 0034 0 JEQ RLOOP 332FFA145 0037 0 RD INPUT DB2032150 003A 0 COMPR A,S A004155 003C 0 JEQ EXIT 332008160 003F 0 STCH BUFFER,X 57A02F165 0042 0 TIXR T B850170 0044 0 JLT RLOOP 3B2FEA175 0047 0 EXIT STX LENGTH 13201F180 004A 0 RSUB 4F0000183 0006 1 USE CDATA185 0006 1 INPUT BYTE XF1 F1
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
79/122
79MC9224- System SoftwareDepartment of Computer Applications
ADHIPARASAKTHI ENGINEERING COLLEGEMelmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
195 .200 . WRITE RECORD FROM BUFFER205 .208 004D 0 USE210 004D 0 WRREC CLEAR X B410212 004F 0 LDT LENGTH 772017
215 0052 0 WLOOP TD = X05 E3201B220 0055 0 JEQ WLOOP 332FFA225 0058 0 LDCH BUFFER,X 53A016230 005B 0 WD = X05 DF2012235 005E 0 TIXR T B850240 0060 0 JLT WLOOP 3B2FEF245 0063 0 RSUB 4F0000252 0007 1 USE CDATA253 LTORG
0007 1 * = CEOF 454F46000A 1 * = X05 05
255 END FIRST
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
80/122
80MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Pass 1 A separate location counter for each program block
Save and restore LOCCTR when switch between blocks At the beginning of a block, LOCCTR is set to 0.
Assign each label an address relative to the start of the block
Store the block name or number in the SYMTAB along with the assignedrelative address of the labelIndicate the block length as the latest value of LOCCTR for each blockat the end of Passssss1
Assign to each block a starting address in the object program byconcatenating the program blocks in a particular order
Pass 2The address of each symbol can be computed by adding the assignedblock starting address and the relative address of the symbol to thatblock
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
81/122
81MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Line Loc/Block Source statement Object Code 5 0000 0 COPY START 010 0000 0 FIRST STL RETADR 17202D15 0003 0 CLOOP JSUB RDREC 4B202120 0006 0 LDA LENGTH 03202625 0009 0 COMP #0 29000030 000C 0 JEQ ENDFIL 33200635 000F 0 JSUB WRREC 4B203B40 0012 0 J CLOOP 3F2FEE45 0015 0 ENDFIL LDA =CEOF 03205550 0018 0 STA BUFFER 0F205655 001B 0 LDA #3 01000360 001E 0 STA LENGTH 0F204865 0021 0 JSUB WRREC 4B202970 0024 0 J @RETADR 3E203F92 0000 1 USE CDATA95 0000 1 RETADR RESW 1100 0003 1 LENGTH RESW 1103 0000 2 USE CBLKS105 0000 2 BUFFER RESB 4096106 1000 2 BUFEND EQU *107 1000 MAXLEN EQU BUFEND - BUFFER
(Figure 2.12)
3 blocks:Default (0)CDATA (1)CBLKS (2)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
82/122
82MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
115 . READ RECORD INTO BUFFER120 .123 0027 0 USE125 0027 0 RDREC CLEAR X B41030 0029 0 CLEAR A B400132 002B 0 CLEAR S B440133 002D 0 +LDT #MAXLEN 75101000135 0031 0 RLOOP TD INPUT E32038140 0034 0 JEQ RLOOP 332FFA145 0037 0 RD INPUT DB2032150 003A 0 COMPR A,S A004155 003C 0 JEQ EXIT 332008160 003F 0 STCH BUFFER,X 57A02F165 0042 0 TIXR T B850170 0044 0 JLT RLOOP 3B2FEA175 0047 0 EXIT STX LENGTH 13201F180 004A 0 RSUB 4F0000183 0006 1 USE CDATA185 0006 1 INPUT BYTE XF1 F1
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
83/122
83MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
195 .200 . WRITE RECORD FROM BUFFER205 .208 004D 0 USE210 004D 0 WRREC CLEAR X B410212 004F 0 LDT LENGTH 772017
215 0052 0 WLOOP TD = X05 E3201B220 0055 0 JEQ WLOOP 332FFA225 0058 0 LDCH BUFFER,X 53A016230 005B 0 WD = X05 DF2012235 005E 0 TIXR T B850240 0060 0 JLT WLOOP 3B2FEF245 0063 0 RSUB 4F0000252 0007 1 USE CDATA253 LTORG
0007 1 * = CEOF 454F46000A 1 * = X05 05
255 END FIRST
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
84/122
84MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
At the end of pass1, assembler constructs a tabEach source line is given a relative address and a blocknumber
Absolute symbol has no block number (line 107)20 0006 0 LDA LENGTH 032060
LENGTH = (Block 1) + 0003 = 0066 + 0003 = 0069LOCCTR = (Block 0) + 0009 = 0009Displacement = 0069 0009 = 060
Block Name Block Number Address Length
(default) 0 0000 066CDATA 1 0066 000B
CBLKS 2 0071 1000
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
85/122
85MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
Program readabilityNo extended format instructions (lines 15, 35, 65)No need for base relative addressing (line 13, 14)LTORG is used to make sure the literals are placedahead of any large data areas (line 253)
Object codeIt is not necessary to physically rearrange the
generated code in the object program; loader canhandle itSee Fig. 2.13, Fig. 2.14
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
86/122
86MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
CDATA
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
87/122
87MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.4. Machine-Independent Assembler Features Program Blocks
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
88/122
88MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program LinkingControl sectionsMost often used for subroutines or other logicalsubdivisions of a program
Programmer can assemble, manipulate, and loadeach of these control sections separatelyInstructions in one control section may need to referto instructions or data in another section
Thus, there should be some means for linking controlsections togetherFig. 2.15, 2.16: three control sections (COPY, RDREC,WRREC)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
89/122
89MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
(Figure 2.16)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
90/122
90MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
91/122
91MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
92/122
92MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program LinkingExternal definition
EXTDEF name [, name]Declare symbols that are defined in this control section and used byother sections
External referenceEXTREF name [,name]
Declare symbols that are used in this control section and are definedelsewhere
For EXTREF labels, assembler has no idea where the correspondingcontrol section will be loaded use 015 0003 CLOOP +JSUB RDREC 4B100000
160 0017 +STCH BUFFER,X 57900000190 0028 MAXLEN WORD BUFEND-BUFFER 000000
External Definition and References
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
93/122
93MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
Assembler must include information in object program that willcause loader to insert proper values where requiredDefine record
Col. 1 DCol. 2-7 Name of external symbol defined in this control
sectionCol. 8-13 Relative address within this control section (hex)Col.14-73 Repeat info in Col. 2-13 for other external symbols
Refer recordCol. 1 RCol. 2-7 Name of external symbol referred to in this sectionCol. 8-73 Name of other external reference symbols
Implementation
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
94/122
94MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
Modification recordCol. 1 MCol. 2-7 Starting address of the field to be modified (hex)Col. 8-9 Length of the field to be modified, in half-bytes (hex)Col.11-16 External symbol whose value is to be added to or subtractedfrom the indicated fieldNote: control section name is automatically an external symbol, i.e. it isavailable for use in Modification records.
ExampleFigure 2.17M00000405+RDRECM00000705+COPY
Modification Record
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
-
8/12/2019 Ss Unit-iiassembler 2007
95/122
95MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
H COPY 000000 001033D BUFFER 00033 BUFEND 001033 LENGTH 00002DR RDREC WRRECT 000000 1D 172027 4B100000 032023 290000 332007 4B100000 ...T 00001D 0D 010003 0F200A 4B10000 3E2000T 000030 03 454F46M 000004 05+RDRECM 000011 05+WRRECM 000024 05+WRRECE 000000
Figure 2.17 (1/2)
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
l h
-
8/12/2019 Ss Unit-iiassembler 2007
96/122
96MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program LinkingH RDREC 000000 00002BR BUFFER LENGTH BUFENDT 000000 1D B410 B400 B440 77201F E3201B 332FFA DB2015 ...T 00001D 0E 3B2FE9 13100000 4F0000 F1 000000
M 000018 05+BUFFERM 000021 05+LENGTHM 000028 06+BUFENDM 000028 06-BUFFERE
H WRREC 000000 00001CR LENGTH BUFFERT 000000 1C B410 77100000 E32012 332FFA 53900000 DF2008 ...M 000003 05+LENGTHM 00000D 05+BUFFERE
Figure 2.17 (2/2)
190 MAXLEN WORD BUFEND - BUFFER
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
M l h 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
97/122
97MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.3.5. Machine-Independent Assembler Features Control section
and Program Linking
Earlier definitionsRequired all of the relative terms be paired in an expression (anabsolute expression), or that all except one be paired (a relative
expression)New restriction
Both terms in each pair must be relative within the same controlsectionEx: BUFEND-BUFFER
Ex: RDREC-COPYIn general, assembler cannot determine whether or not theexpression is legal at assembly time. This work will be handledby a linking loader.
External Reference in Expressions
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
M l h 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
98/122
98MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Main problemForward references
Data items
Labels on instructionsSolution
Data items: require all such areas be defined
before they are referencedLabels on instructions: no good solution
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
M l th 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
99/122
99MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Two types of one-pass assemblerType 1: Load-and-go
Produces object code directly in memory for
immediate executionType 2:
Produces usual kind of object code for laterexecution
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
M l th 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
100/122
100MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
CharacteristicsUseful for program development and testing
Avoids the overhead of writing the object program
out and reading it backBoth one-pass and two-pass assemblers can bedesigned as load-and-goHowever one-pass also avoids the overhead of an
additional pass over the source programFor a load-and-go assembler, the actual addressmust be known at assembly time, we can use anabsolute program
Load-and-Go Assembler
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
101/122
101MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Load-and-Go Assembler Assembler operations:
1. Omit address translation for any undefined symbol2. Insert the symbol into SYMTAB, mark it undefined3. The address that refers to the undefined symbol is
added to a list of forward references associated withthe symbol table entry
4. When the definition for a symbol is encountered, theproper address for the symbol is then inserted intoany instructions previously generated according tothe forward reference list
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
102/122
102MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Load-and-Go Assembler
At the end of the program Any SYMTAB entries that are still marked with *indicate undefined symbolsSearch SYMTAB for the symbol named in the ENDstatement and jump to this location to beginexecution
The actual starting address must be specified atassembly time
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
103/122
103MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.18Line Loc Source statement Object code0 1000 COPY START 10001 1000 EOF BYTE CEOF 454F462 1003 THREE WORD 3 0000033 1006 ZERO WORD 0 0000004 1009 RETADR RESW 15 100C LENGTH RESW 1
6 100F BUFFER RESB 409610 200F FIRST STL RETADR 14100915 2012 CLOOP JSUB RDREC 48203D20 2015 LDA LENGTH 00100C25 2018 COMP ZERO 28100630 201B JEQ ENDFIL 30202435 201E JSUB WRREC 48206240 2021 J CLOOP 3C201245 2024 ENDFIL LDA EOF 00100050 2027 STA BUFFER 0C100F55 202A LDA THREE 00100360 202D STA LENGTH 0C100C65 2030 JSUB WRREC 48206270 2033 LDL RETADR 08100975 2036 RSUB 4C0000
ADHIPARASAKTHI ENGINEERING COLLEGE
OmSakthi
Melmaruvathur 603 319
-
8/12/2019 Ss Unit-iiassembler 2007
104/122
104MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.19(a)
Before Line 40Memory Address Contents
1000 454F4600 00030000 00xxxxxx xxxxxxxx1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
.
.2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14
2010 100948-- --00100C 28100630 ----48--2020 --3C2012
.
. Address unknown yet
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
105/122
105MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.19(a) - SYMTAB
LENGTH 100C RDREC * THREE 1003
ZERO 1006 WRREC * EOF 1000 ENDFIL * RETADR 1009
BUFFER 100F CLOOP 2012 FIRST 200F ... ...
Symbol Value
2013
201F
201C
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
106/122
106MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur-603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.19(a)
After Line 45 Memory Address Contents
1000 454F4600 00030000 00xxxxxx xxxxxxxx
1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx..
2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14
2010 100948-- --00100C 28100630 2024 48--2020 --3C2012 001000
.
.
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
107/122
107MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur 603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.19(a) - SYMTAB
LENGTH 100C RDREC * THREE 1003
ZERO 1006 WRREC * EOF 1000 ENDFIL 2024 RETADR 1009
BUFFER 100F CLOOP 2012 FIRST 200F ... ...
Symbol Value
2013
201F
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
108/122
108MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur 603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.18110 .115 . SUB TO READ RECORD INTO BUFFER120 .121 2039 INPUT BYTE XF1 F1122 203A MAXLEN WORD 4096 001000124 .
125 203D RDREC LDX ZERO 041006130 2040 LDA ZERO 001009135 2043 RLOOP TD INPUT E02039140 2046 JEQ RLOOP 302043145 2049 RD INPUT D82039150 204C COMP ZERO 281006155 204F JEQ EXIT 30205B
160 2052 STCH BUFFER,X 54900F165 2055 TIX MAXLEN 2C203A170 2058 JLT RLOOP 382043175 205B EXIT STX LENGTH 10100C180 205E RSUB 4C0000
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
109/122
109MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur 603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.19 (b)
After Line 160 Memory Address Contents
1000 454F4600 00030000 00xxxxxx xxxxxxxx1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
.2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx142010 10094820 3D00100C 28100630 202448--2020 --3C2012 0010000C 100F0010 030C100C2030 48----08 10094C00 00F10010 000410062040 001006E0 20393020 43DB2039 281006302050 ----5490 0F
.
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
110/122
110MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur 603 319
2.4. 1 Assembler Design Options One Pass Assembler
LENGTH 100C RDREC 203D
THREE 1003
ZERO 1006
WRREC *
EOF 1000
ENDFIL 2024
RETADR 1009
BUFFER 100F
CLOOP 2012
FIRST 200F
MAXLEN 203A
INPUT 2039
EXIT *
RLOOP 2043
... ...
201F
2031
2050
Program for one pass assembler
Fig 2.19 (b)
After Line 160
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
111/122
111MC9224- System SoftwareDepartment of Computer Applications
Melmaruvathur 603 319
2.4. 1 Assembler Design Options One Pass Assembler
Program for one pass assembler
Fig 2.18195 .200 . SUB TO WRITE RECORD FROM BUFFER205 .206 2061 OUTPUT BYTE X05 05207 .210 2062 WRREC LDX ZERO 041006215 2065 WLOOP TD OUTPUT E02061220 2068 JEQ WLOOP 302065225 206B LDCH BUFFER,X 50900F230 206E WD OUTPUT DC2061235 2071 TIX LENGTH 2C100C240 2074 JLT WLOOP 382065245 2077 RSUB 4C0000255 END FIRST
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
112/122
112MC9224- System SoftwareDepartment of Computer Applications
2.4. 1 Assembler Design Options One Pass Assembler
Type 2 AssemblerWill produce object code Assembler operations:
Forward references are entered into list as beforeInstruction referencing are written into object file as a Textrecord, even with incorrect addressesWhen definition of a symbol is encountered, assembler mustgenerate another Text record with the correct operandaddressLoader is used to insert correct addresses into instructionswith forward references that could not be handled by theassemblerObject program records must be kept in original order whenthey are presented to the loader
-
8/12/2019 Ss Unit-iiassembler 2007
113/122
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
114/122
114MC9224- System SoftwareDepartment of Computer Applications
2.4. 1 Assembler Design Options One Pass Assembler
Type 2 Assembler
Fig. 2.20
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
115/122
115MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
Restriction on EQU and ORGNo forward reference, since symbols value cant bedefined during the first pass
Example: ALPHA EQU BETABETA EQU DELTADELTA RESW 1
Assemblers with 2 passes cannot resolve
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
116/122
116MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
Resolve forward references with as manypasses as needed
Portions that involve forward references in symboldefinition are saved during Pass 1
Additional passes through stored definitionsFinally a normal Pass 2
Example implementation:
Use link lists to keep track of whose value dependon an undefined symbol
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
117/122
117MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
1 HALFSZ EQU MAXLEN/2
2 MAXLEN EQU BUFEND-BUFFER
3 PREVBT EQU BUFFER-1
...4 BUFFER RESB 4096
5 BUFEND EQU *
HALFSZ &1 MAXLEN/2
MAXLEN *
1 symbol undefined
HALFSZ
Fig. 2.21 (a)
After Pass 1
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
118/122
118MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
1 HALFSZ EQU MAXLEN/2
2 MAXLEN EQU BUFEND-BUFFER
3 PREVBT EQU BUFFER-1...
4 BUFFER RESB 4096
5 BUFEND EQU *
BUFEND *
HALFSZ &1 MAXLEN/2
MAXLEN &2 BUFEND-
BUFFER
BUFFER * MAXLEN
MAXLEN
HALFSZ
Fig. 2.21 (c)
MAXLEN defined
-
8/12/2019 Ss Unit-iiassembler 2007
119/122
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
120/122
120MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
Fig. 2.21 (d)
PERVBT defined1 HALFSZ EQU MAXLEN/2
2 MAXLEN EQU BUFEND-BUFFER
3 PREVBT EQU BUFFER-1
...
4 BUFFER RESB 4096
5 BUFEND EQU *
BUFEND *
HLFSZ &1 MAXLEN/2
PREVBT &1 BUFFER-1
MAXLEN &2 BUFEND-BUFFER
BUFFER *
MAXLEN
PREVBT
HALFSZ
MAXLEN
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
121/122
121MC9224- System SoftwareDepartment of Computer Applications
2.4.2 Assembler Design Options Multi Pass Assembler
Fig. 2.21 (e)
After Line 41 HALFSZ EQU MAXLEN/2
2 MAXLEN EQU BUFEND-BUFFER
3 PREVBT EQU BUFFER-1
...
4 BUFFER RESB 4096
5 BUFEND EQU *
BUFEND *
HLFSZ &1 MAXLEN/2
PREVBT 1033
MAXLEN &1 BUFEND-BUFFER
BUFFER 1034
MAXLEN
Assumeloc=1034
HALFSZ
ADHIPARASAKTHI ENGINEERING COLLEGEOmSakthi
Melmaruvathur-603 319
-
8/12/2019 Ss Unit-iiassembler 2007
122/122
2.4.2 Assembler Design Options Multi Pass Assembler
Fig. 2.21 (f)
After Line 5
1 HALFSZ EQU MAXLEN/2
2 MAXLEN EQU BUFEND-BUFFER
3 PREVBT EQU BUFFER-1
...
4 BUFFER RESB 4096
5 BUFEND EQU *
BUFEND 2034
HLFSZ 800
PREVBT 1033
MAXLEN 1000
BUFFER 1034