Download presentation
Presentation is loading. Please wait.
1
ADHIPARASAKTHI ENGINEERING COLLEGE
CN-MC1701 Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Unit – II Assembler MC9224 – System Software
2
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Outline Basic Assembler Functions A simpler SIC Assembler Assembler Algorithm and Data Structures Machine-Dependent Assembler Features Instruction Formats and Addressing Modes Program Location Machine-Independent Assembler Features Literals Symbol-Defining Statements Expressions Program Blocks Control Section and Program Linking Assembler Design Options One-Pass Assembler Multi-Pass Assembler Implementation Examples MASM Assembler
3
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.1. Basic Assembler Functions Example Program SIC Assembler Purpose 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 character End of the file is indicated by a zero-length record Subroutines (JSUB, RSUB) RDREC, WRREC Save link register first before nested jump
4
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.1. Basic Assembler Functions 5 COPY START 1000 LOAD PROG AT LOC 1000 10 FIRST STL RETADR SAVE RETURN ADDRESS 15 CLOOP JSUB RDREC READ INPUT RECORD 20 LDA LENGTH TEST FOR EOF (LENGTH = 0) 25 COMP ZERO 30 JEQ ENDFIL EXIT IF EOF FOUND 35 JSUB WRREC WRITE OUTPUT RECORD 40 J CLOOP LOOP 45 ENDFIL LDA EOF INSERT END OF FILE MARKER 50 STA BUFFER 55 LDA THREE SET LENGTH = 3 60 STA LENGTH 65 JSUB WRREC WRITE EOF 70 LDL RETADR GET RETURN ADDRESS 75 RSUB RETURN TO CALLER 80 EOF BYTE C’EOF’ 85 THREE WORD 3 90 ZERO WORD 0 95 RETADR RESW 1 100 LENGTH RESW 1 105 BUFFER RESB BYTE BUFFER AREA
5
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.1. Basic Assembler Functions 110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER 120 . 125 RDREC LDX ZERO CLEAR LOOP COUNTER 130 LDA ZERO CLEAR A TO ZERO 135 RLOOP TD INPUT TEST INPUT DEVICE 140 JEQ RLOOP LOOP UNTIL READY 145 RD INPUT READ CHARACTER INTO A 150 COMP ZERO TEST FOR END OF RECORD 155 JEQ EXIT EXIT LOOP IF EOR 160 STCH BUFFER,X STORE CHAR IN BUFFER 165 TIX MAXLEN LOOP UNLESS MAX LENGTH 170 JLT RLOOP HAS BEEN REACHED 175 EXIT STX LENGTH SAVE RECORD LENGTH 180 RSUB RETURN TO CALLER 185 INPUT BYTE X’F1’ CODE FOR INPUT DEVICE 190 MAXLEN WORD 4096
6
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.1. Basic Assembler Functions 195 . 200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 . 210 WRREC LDX ZERO CLEAR LOOP COUNTER 215 WLOOP TD OUTPUT TEST OUTPUT DEVICE 220 JEQ WLOOP LOOP UNTIL READY 225 LDCH BUFFER,X GET CHAR FROM BUFFER 230 WD OUTPUT WRITE CHARACTER 235 TIX LENGTH LOOP UNTIL ALL CHAR 240 JLT WLOOP HAVE BEEN WRITTEN 245 RSUB RETURN TO CALLER 250 OUTPUT BYTE X’05’ CODE FOR OUTPUT DEVICE 255 END FIRST
7
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.1. Basic Assembler Functions Assembler Directives Pseudo-Instructions / Basic assembler directives Not translated into machine instructions Providing information to the assembler Basic assembler directives START – Specifies starting memory address of object program END – Marks the end of the program BYTE – Generate Character / Hexadecimal constant – 1 byte WORD – Generate 1 word constant RESB – Reserve the indicated number of bytes for data area RESW – Reserve the indicated number of words for data area
8
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler Mnemonic code (or instruction name) opcode Symbolic operands (e.g., variable names) Machine addresses Choose the proper instruction format and addressing mode Constants Equivalent Internal Machine representation Output to object files and listing files
9
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Example Program & Object Code Line Loc Source statement Object code COPY START 1000 FIRST STL RETADR CLOOP JSUB RDREC LDA LENGTH COMP ZERO 30 100C JEQ ENDFIL 35 100F JSUB WRREC J CLOOP 3C1003 ENDFIL LDA EOF 00102A STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 JSUB WRREC LDL RETADR RSUB 4C0000
10
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Example Program & Object Code Line Loc Source statement Object code 80 102A EOF BYTE C’EOF’ 454F46 85 102D THREE WORD ZERO WORD RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096
11
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Example Program & Object Code 110 . SUB TO READ RECORD INTO BUFFER 120 . RDREC LDX ZERO C LDA ZERO F RLOOP TD INPUT E0205D JEQ RLOOP 30203F RD INPUT D8205D COMP ZERO B JEQ EXIT E STCH BUFFER,X TIX MAXLEN 2C205E JLT RLOOP 38203F EXIT STX LENGTH A RSUB 4C0000 D INPUT BYTE X’F1’ F1 E MAXLEN WORD
12
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Example Program & Object Code 195 . SUB TO WRITE RECORD FROM BUFFER 205 . WRREC LDX ZERO WLOOP TD OUTPUT E02079 JEQ WLOOP A LDCH BUFFER,X D WD OUTPUT DC2079 TIX LENGTH 2C1036 JLT WLOOP RSUB 4C0000 OUTPUT BYTE X’05’ 05 255 END FIRST
13
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler Mnemonic code (or instruction name) opcode Examples: STL 1033 LDA 1036
14
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Converting Symbol to Numbers Isn’t it straightforward? Isn’t it simply the sequential processing of the source program, one line at a time? Not so, if we have forward references we don’t know the value of the symbol, because it is defined later in the code Need two pass Assembler Loc Label Operator Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … … … … … J CLOOP 1033 RETADR RESW 1
15
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Symbolic Operands We are not likely to write memory addresses directly in our code Instead, we will define variable names Other examples of symbolic operands: Labels (for jump instructions) Subroutines Constants
16
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Two Pass Assembler Pass1 Scan the source program Identify the label definitions and assign addresses Pass2 All other assembler operations Load and Execution
17
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Record Types Object Program contains three Records Header Col. 1 H Col. 2~7 Program name Col. 8~ Starting address (hex) Col Length of object program in bytes (hex) Text Col.1 T Col.2~7 Starting address in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69 Object code ( )/6=10 instructions End Col E Col.2~7 Address of first executable instruction (hex)
18
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler – Object Program H^COPY ^001000^00107A T^001000^1E^141033^482039^001036^281030^301015^482061^ 3C1003^00102A^0C1039^00102D T^00101E^15^0C1036^482061^081044^4C0000^454F46^000003^000000 T^002039^1E^041030^001030^E0205D^30203F^D8205D^281030^302057^549039^2C205E^38203F T^002057^1C^101036^4C0000^F1^001000^041030^E02079^302064^509039^DC2079^2C1036 T^002073^07^382064^4C0000 ^05 E^ starting address
19
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur A Simple SIC Assembler Functions of a 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 by translating opcode and symbolic operands 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
20
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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 2 Intermediate file OPTAB SYMTAB Source program Object code
21
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures OPTAB (Operation Code Table) Content Mnemonic names, machine code (instruction format, length for SIC/XE) etc. Characteristic Static table (assembler itself written) Implementation Array or hash table(mnemonic operation code as key), easy for search Usage Pass 1 - look up and validate mnemonic operation codes in the source program Pass 2 – translate opcodes into machine language
22
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures SYMTAB (Symbol Table) Content Label name, value, flag, (type, length for data area ) etc. Characteristic Dynamic table (insert, delete, search) Implementation Hash table, non-random keys, hashing function Usage Pass 1 - enter symbol names into SYMTAB along with the assign address ( from LOCCTR) Pass 2 – look up symbols, fetch address and insert in object code COPY 1000 FIRST CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039
23
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Intermediate File Pass1 and pass2 use source program as input. Other information should be passed between two passes. Pass 1 writes an intermediate file Each source statement together with its assigned address Error indicators Used as input for pass 2
24
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler
25
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler
26
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler
27
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler
28
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Algorithm and Data Structures Object Program Loading 1000 141033 482039 001036 281030 301015 1003 1006 1009 100C 081033 1024 4C0000 1027 454F46 102A 000003 102D 000000 1030 STL RETADR JSUB RDREC LDA LENGTH COMP ZERO JEQ ENDFIL LDL RETADR RSUB ‘E’ ‘O’ ‘F’ 3 xxxxxx 1033 … 1036 BYTE C’EOF’ WORD 3 WORD 0 RESW 1 LENGTH RETADR
29
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.2. Machine-Dependent Assembler Features SIC/XE Assembler We have learned the 2-pass assembler for SIC What’s new for SIC/XE? More addressing modes Program relocation
30
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes 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)
31
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Register translation – during pass 2 Register name (A, X, L, B, S, T, F, PC, SW) translated to their ids (0,1, 2, 3, 4, 5, 6, 8, 9) Use separate table or may be preloaded in SYMTAB Address translation Register-memory instructions: try PC-relative first, then base-relative addressing Assembler makes its own decision User must specify extended format (format 4), otherwise error will be generated by the assembler Format 3: 12-bit displacement Base-relative: 0~ PC-relative: -2048~2047 Format 4: 20-bit address field
32
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Line Loc Source statement Object code COPY START 0 FIRST STL RETADR 17202D LDB #LENGTH 69202D 13 BASE LENGTH CLOOP +JSUB RDREC 4B101036 20 000A LDA LENGTH 25 000D COMP # JEQ ENDFIL JSUB WRREC 4B10105D J CLOOP 3F2FEC 45 001A ENDFIL LDA EOF 50 001D STA BUFFER 0F2016 LDA # STA LENGTH 0F200D JSUB WRREC 4B10105D 70 002A J @RETADR 3E2003 80 002D EOF BYTE C’EOF’ 454F46 RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096
33
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes READ RECORD INTO BUFFER 120 . RDREC CLEAR X B410 CLEAR A B400 A CLEAR S B440 C +LDT # RLOOP TD INPUT E32019 JEQ RLOOP 332FFA RD INPUT DB2013 COMPR A,S A004 B JEQ EXIT E STCH BUFFER,X 57C003 TIXR T B850 JLT RLOOP 3B2FEA EXIT STX LENGTH RSUB 4F0000 C INPUT BYTE X’F1’ F1
34
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes 195 . WRITE RECORD FROM BUFFER 205 . D WRREC CLEAR X B410 12 105F LDT LENGTH WLOOP TD OUTPUT E32011 JEQ WLOOP 332FFA LDCH BUFFER,X 53C003 B WD OUTPUT DF2008 E TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 OUTPUT BYTE X’05’ 05 255 END FIRST
35
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes PC Relative Addressing FIRST STL RETADR 17202D Displacement= RETADRPC = 00300003 = 02D J CLOOP 3F2FEC Displacement= CLOOPPC= 0006001A= 14= FEC OPCODE e Address n i x b p (02D)16 1 OPCODE e Address n i x b p (FEC)16 1
36
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Base Relative Addressing Mode BASE register and directive: 12 LDB #LENGTH 13 BASE LENGTH Base register is under the control of programmer BASE directive tells assembler that LENGHTH is base address; NOBASE releases the binding, until B value will be used as Base address E STCH BUFFER, X 57C003 Displacement= BUFFERB = 00360033 = 3 Compare lines 20 and 175 (PC vs Base addressing) OPCODE e Address n i x b p (003)16 1
37
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Base Relative Addressing Mode Why cannot we use PC-relative? Assembler knows the PC value at execution time, it cannot be changeable Base register is under the control of programmer, and set initially and changeable
38
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Immediate Address Translation LDA # C LDT # OPCODE e Address n i x b p (003)16 1 OPCODE e Address n i x b p 1 (01000)16
39
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Immediate Address Translation LDB #LENGTH 69202D LDB #LENGTH The immediate operand is the value of the symbol LENGTH, which is the address assigned to LENGTH LENGTH=0033=PC+displacement= D OPCODE e Address n i x b p (02D)16 1 OPCODE e Address n i x b p (033)16 1
40
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Instruction Formats and Addressing Modes Indirect Address Translation Target addressing is computed as usual (PC-relative or BASE-relative) Only the n bit is set to 1 70 002A 3E2003 TA=RETADR=0030 TA=(PC)+displacement=002D+0003 OPCODE e Address n i x b p (003)16 1
41
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Need for program relocation Example : If program starts at 1000 55 101B LDA THREE 00102D If program starts at 2000 55 201B LDA THREE 00202D Some lines need not be modified (line 85, value 3) Assembler does not know that where the program will be loaded, but it can inform to loader via modification records.
42
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Loaded at 0000 Loaded at 5000 Loaded at 7420
43
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Example Fig. 2.2 Absolute program, starting address 1000 ==== 2000 COPY START 1000 FIRST STL RETADR CLOOP JSUB RDREC LDA LENGTH COMP ZERO 30 200C 100C JEQ ENDFIL 35 200F 100F JSUB WREC J CLOOP 3C C2003 ENDFIL LDA EOF A A STA BUFFER 0C C2039 55 201B 101B LDA THREE D D 60 201E 101E STA LENGTH 0C C2036 JSUB WREC LDL RETADR RSUB 4C C0000 80 202A 102A EOF BYTE C'EOF' 454E E46 85 202D 102D THREE WORD ZERO WORD RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 ==== 2000
44
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Example Fig. 2.6: Except for absolute address, rest of the instructions need not be modified not a memory address (immediate addressing) PC-relative, Base-relative Parts requiring modification at load time are those with absolute addresses COPY START 0 FIRST STL RETADR D D LDB #LENGTH D D BASE LENGTH CLOOP +JSUB RDREC 4B B102036 20 100A A LDA LENGTH 25 100D D COMP # JEQ ENDFIL JSUB WRREC 4B10105D 4B10205D J CLOOP 3F2FEC F2FEC 45 101A A ENDFIL LDA EOF 50 101D D STA BUFFER 0F F2016 LDA # STA LENGTH 0F200D F200D JSUB WRREC 4B10105D 4B10205D 70 102A A 3E E2003 80 102D D EOF BYTE C'EOF' 454F F46 RETADR RESW 1 BUFFER RESB 4096 == 1000
45
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Making Program Relocation Easier Use relative addresses Did you notice that we didn’t modify the addresses for JEQ, JLT and J instructions? We didn’t modify the addresses for RETADR, LENGTH, and BUFFER in Figure 2.6 either. The sample SIC/EX program is easier Mostly PC or base relative Only extended format instructions have direct addresses and require modification
46
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Relocatable Program An object program that contains information needed for address modification for loading Modification record Col 1 M Col 2-7 Starting location of the address field to be modified, relative to the beginning of the program (count in bytes) Col length of the address field to be modified, in half-bytes (address field to be modified may not occupy an integral number of bytes, e.g. 20 bits)
47
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Object File with M-Records Modification records are added to the object files. (See pp.67 and Figure 2.8.) Example: HCOPY T D 17202D…4B101036… T00001D …… … M Modification Record …… E000000
48
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Modification Record 0009 3 6 1 0 4 B 2 D 0008 0007 0006 0005 +JSUB RDREC 0004 2 0 6 9 1 7 0003 0002 0001 0000 LDB #LENGTH STL RETADR 000C 2 6 0 3 000B 000A LDA LENGTH M Address 0007 5 half-bytes
49
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Program Relocation Object Code
50
Design idea Example (Fig. 2.10)
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Design idea Let programmers write the value of a constant operand as a part of the instruction that uses it Avoids having to define the constant elsewhere in the program and make up a label for it Example (Fig. 2.10) A ENDFIL LDA =C’EOF’ WLOOP TD =X’05’
51
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program COPY START 0 FIRST STL RETADR 17202D LDB #LENGTH 69202D 14 BASE LENGTH CLOOP +JSUB RDREC 4B101036 20 000A LDA LENGTH 25 000D COMP # JEQ ENDFIL JSUB WRREC 4B10105D J CLOOP 3F2FEC 45 001A ENDFIL LDA =C’EOF’ 50 001D STA BUFFER 0F2016 LDA # STA LENGTH 0F200D JSUB WRREC 4B10105D 70 002A 3E2003 93 LTORG RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 BUFEND EQU * MAXLEN EQU BUFEND - BUFFER
52
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program READ RECORD INTO BUFFER 120 . RDREC CLEAR X B410 CLEAR A B400 A CLEAR S B440 C +LDT #MAXLEN RLOOP TD INPUT E32019 JEQ RLOOP 332FFA RD INPUT DB2013 COMPR A,S A004 B JEQ EXIT E STCH BUFFER,X 57C003 TIXR T B850 JLT RLOOP 3B2FEA EXIT STX LENGTH RSUB 4F0000 C INPUT BYTE X’F1’ F1
53
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program 195 . WRITE RECORD FROM BUFFER 205 . D WRREC CLEAR X B410 F LDT LENGTH WLOOP TD =X’05’ E32011 JEQ WLOOP FFA LDCH BUFFER,X 53C003 B WD =X’05’ DF2008 E TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 END FIRST
54
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.2. Machine-Independent Assembler Features - Literals Literal vs. Immediate Operands Immediate operands Operand value is assembled as part of the machine instruction LDA # Literals The assembler generates the specified value as a constant at some other memory location 45 001A ENDFIL LDA =C’EOF’ Compare (Fig. 2.6) 45 001A ENDFIL LDA EOF 80 002D EOF BYTE C’EOF’ 454F46
55
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Literal Implementation (1/4) Literal pools All the literals used in the program grouped together in to one or more literal pools Normally literals are placed into a pool at the end of the program See Fig (after END statement) In some cases, it is desirable to place literals into a pool at some other location in object program Use assembler directive LTORG: create a literal pool that contains all of the literal operands used since the previous LTROG, and place it where LTORG was encountered Reason: keep literal operand close to the instruction
56
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program with Literal Implementation COPY START 0 FIRST STL RETADR 17202D LDB #LENGTH 69202D 14 BASE LENGTH CLOOP +JSUB RDREC 4B101036 20 000A LDA LENGTH 25 000D COMP # JEQ ENDFIL JSUB WRREC 4B10105D J CLOOP 3F2FEC 45 001A ENDFIL LDA =C’EOF’ 50 001D STA BUFFER 0F2016 LDA # STA LENGTH 0F200D JSUB WRREC 4B10105D 70 002A 3E2003 93 LTORG 002D * =C’EOF’ 454F46 RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 BUFEND EQU * MAXLEN EQU BUFEND - BUFFER
57
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program with Literal Implementation READ RECORD INTO BUFFER 120 . RDREC CLEAR X B410 CLEAR A B400 A CLEAR S B440 C +LDT #MAXLEN RLOOP TD INPUT E32019 JEQ RLOOP 332FFA RD INPUT DB2013 COMPR A,S A004 B JEQ EXIT E STCH BUFFER,X 57C003 TIXR T B850 JLT RLOOP 3B2FEA EXIT STX LENGTH RSUB 4F0000 C INPUT BYTE X’F1’ F1
58
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Example Program with Literal Implementation 195 . WRITE RECORD FROM BUFFER 205 . D WRREC CLEAR X B410 F LDT LENGTH WLOOP TD =X’05’ E32011 JEQ WLOOP FFA LDCH BUFFER,X 53C003 B WD =X’05’ DF2008 E TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 END FIRST 1076 * =X’05’ 05
59
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Literal Implementation (2/4) Duplicate literals WLOOP TD =X’05’ B WD =X’05’ Assembler should recognize duplicate literals and store only one copy of specified data value By comparing defining character string, e.g. =X’05’ By comparing the generated data value, e.g. =C’EOF’ and =X’454F46’, but benefits are usually not great enough to justify the additional complexity in the assembler
60
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.3. Machine-Independent Assembler Features - Literals Literal Implementation (3/4) – Problem of duplicate literal recognition '*' denotes a literal refer to the current value of location counter. Some have same name, but different values. BASE * LDB =* If the literal value represents an 'address' in the program, the assembler must also generate the appropriate 'Modification records'
61
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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/length When LTORG is encountered, assign address to each literal not yet assigned an address, update LOCCTR Pass 2 Search LITTAB for each literal encountered and generate the operand address Data values of literals in literal pool are generated similarly as using BYTE or WORD statements Generate modification record for literals that represent an address in the program
62
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Users can define labels on instructions or data areas The value of a label is the address assigned to the statement Users can also define symbols with values symbol EQU value value can be constants, other symbols, expressions Making source program easier to understand No forward reference
63
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Example 1: replacing symbolic names 133 LDT #4096 replaced as MAXLEN EQU LDT #MAXLEN Example 2: defining mnemonic names for registers A EQU 0 X EQU 1 RMO A,X can be replaced as RMO 0,1
64
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Example 3: defining registers with symbolic namesv(SIC) BASE EQU R1 COUNT EQU R2 INDEX EQU R3 To represent registers 1,2,3…
65
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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 automatically remembered, we can return to the normal use of LOCCTR by simply write ORG
66
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Symbol table structure to support ORG In the data structure Symbol :6 bytes Value :3 bytes Flags :2 bytes If EQU statements are used STAB RESB 1100 SYMBOL EQU STAB VALUE EQU STAB+6 FLAG EQU STAB+9 Symbol Value Flags STAB (100 entries) :
67
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement If ORG statements are used STAB RESB 1100 ORG STAB Set LOCCTR to STAB SYMBOL RESB 6 VALUE RESW Size of each field FLAGS RESB 2 ORG STAB Restore LOCCTR VALUE field fetched by LDA VALUE,X
68
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Restriction with EQU All symbols used in the right –hand side must be defined previously in the program ALPHA RESW 1 BETA EQU ALPHA ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1 Valid Invalid Invalid
69
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Symbol Defining statement Restriction with ORG All symbols used to specify the new location counter value must have been previously defined ORG ALPHA BYTE1 RESB 1 BYTE2 RESB 2 BYTE3 RESB 3 ORG ALPHA RESB 1 Invalid
70
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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 special terms. 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
71
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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)
72
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Expressions Expressions can be Absolute Only absolute terms Relative 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 positive sign. No relative terms may enter into a multiplication or division operation Expressions that do not meet the conditions of either “absolute” or “relative” should be flagged as errors.
73
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Expressions Handling relative terms in SYMTAB Assembler needs to track type of an expression, to generate Modification records if needed Need a ‘flag’ in the SYMTAB for indication Absolute value BUFFEND – BUFFER Illegal BUFFEND + BUFFER 100 – BUFFER 3* BUFFER Symbol Type Flag RETADR R 0030 BUFFER 0036 BUFEND 1036 MAXLEN A 1000
74
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Allow the generated machine instructions and data to appear in the object program in a different order Gather all code segments, data segments and stack segments Program blocks vs. Control sections Program blocks Segments of code that are rearranged within a single object program unit Control section Segments of code that are translated into independent object program units
75
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Assembler directive : USE USE [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 of the source program Assembler rearrange these segments to gather together the pieces of each block and assign address Separate the program into blocks in a particular order Large buffer area is moved to the end of the object program Program readability is better if data areas are placed in the source program close to the statements that reference them
76
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Three blocks are used default: executable instructions CDATA: all data areas that are less in length CBLKS: all data areas that consists of larger blocks of memory
77
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Line Source statement Object Code COPY START 0 FIRST STL RETADR 17202D CLOOP JSUB RDREC 4B2021 LDA LENGTH COMP # 30 000C 0 JEQ ENDFIL 35 000F 0 JSUB WRREC 4B203B J CLOOP 3F2FEE ENDFIL LDA =C’EOF’ STA BUFFER 0F2056 55 001B 0 LDA # 60 001E 0 STA LENGTH 0F2048 JSUB WRREC 4B2029 E203F USE CDATA RETADR RESW 1 LENGTH RESW 1 USE CBLKS BUFFER RESB 4096 BUFEND EQU * MAXLEN EQU BUFEND - BUFFER (Figure 2.11)
78
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks READ RECORD INTO BUFFER 120 . USE RDREC CLEAR X B410 CLEAR A B400 B CLEAR S B440 D LDT #MAXLEN RLOOP TD INPUT E32038 JEQ RLOOP 332FFA RD INPUT DB2032 A COMPR A,S A004 C JEQ EXIT F STCH BUFFER,X 57A02F TIXR T B850 JLT RLOOP 3B2FEA EXIT STX LENGTH 13201F A RSUB 4F0000 USE CDATA INPUT BYTE X’F1’ F1
79
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks 195 . WRITE RECORD FROM BUFFER 205 . D 0 USE D 0 WRREC CLEAR X B410 F 0 LDT LENGTH WLOOP TD =X’05’ E3201B JEQ WLOOP FFA LDCH BUFFER,X 53A016 B 0 WD =X’05’ DF2012 E 0 TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 USE CDATA LTORG * =C’EOF’ 454F46 000A 1 * =X’05’ 05 END FIRST
80
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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 assigned relative address of the label Indicate the block length as the latest value of LOCCTR for each block at the end of Passssss1 Assign to each block a starting address in the object program by concatenating the program blocks in a particular order Pass 2 The address of each symbol can be computed by adding the assigned block starting address and the relative address of the symbol to that block
81
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Line Loc/Block Source statement Object Code COPY START 0 FIRST STL RETADR 17202D CLOOP JSUB RDREC 4B2021 LDA LENGTH COMP # 30 000C 0 JEQ ENDFIL 35 000F 0 JSUB WRREC 4B203B J CLOOP 3F2FEE ENDFIL LDA =C’EOF’ STA BUFFER 0F2056 55 001B 0 LDA # 60 001E 0 STA LENGTH 0F2048 JSUB WRREC 4B2029 E203F USE CDATA RETADR RESW 1 LENGTH RESW 1 USE CBLKS BUFFER RESB 4096 BUFEND EQU * MAXLEN EQU BUFEND - BUFFER 3 blocks: Default (0) CDATA (1) CBLKS (2) (Figure 2.12)
82
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks READ RECORD INTO BUFFER 120 . USE RDREC CLEAR X B410 CLEAR A B400 B CLEAR S B440 D LDT #MAXLEN RLOOP TD INPUT E32038 JEQ RLOOP 332FFA RD INPUT DB2032 A COMPR A,S A004 C JEQ EXIT F STCH BUFFER,X 57A02F TIXR T B850 JLT RLOOP 3B2FEA EXIT STX LENGTH 13201F A RSUB 4F0000 USE CDATA INPUT BYTE X’F1’ F1
83
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks 195 . WRITE RECORD FROM BUFFER 205 . D 0 USE D 0 WRREC CLEAR X B410 F 0 LDT LENGTH WLOOP TD =X’05’ E3201B JEQ WLOOP FFA LDCH BUFFER,X 53A016 B 0 WD =X’05’ DF2012 E 0 TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 USE CDATA LTORG * =C’EOF’ 454F46 000A 1 * =X’05’ 05 END FIRST
84
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks At the end of pass1, assembler constructs a tab Each source line is given a relative address and a block number Absolute symbol has no block number (line 107) LDA LENGTH LENGTH = (Block 1) = = 0069 LOCCTR = (Block 0) = 0009 Displacement = 0069 – 0009 = 060 Block Name Block Number Address Length (default) 0000 066 CDATA 1 0066 000B CBLKS 2 0071 1000
85
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks Program readability No 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 placed ahead of any large data areas (line 253) Object code It is not necessary to physically rearrange the generated code in the object program; loader can handle it See Fig. 2.13, Fig. 2.14
86
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks CDATA
87
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Program Blocks
88
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking Control sections Most often used for subroutines or other logical subdivisions of a program Programmer can assemble, manipulate, and load each of these control sections separately Instructions in one control section may need to refer to instructions or data in another section Thus, there should be some means for linking control sections together Fig. 2.15, 2.16: three control sections (COPY, RDREC, WRREC)
89
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking COPY START 0 6 EXTDEF BUFFER,BUFEND,LENGTH 7 EXTREF RDREC,WRREC FIRST STL RETADR CLOOP +JSUB RDREC 4B100000 LDA LENGTH 25 000A COMP # 30 000D JEQ ENDFIL JSUB WRREC 4B100000 J CLOOP 3F2FEC ENDFIL LDA =C’EOF’ 50 001A STA BUFFER 0F2016 55 001D LDA # STA LENGTH 0F200A JSUB WRREC 4B100000 E2000 95 002A RETADR RESW 1 D LENGTH RESW 1 LTORG 0030 * =C’EOF’ 454F46 BUFFER RESB 4096 BUFEND EQU * MAXLEN EQU BUFEND - BUFFER (Figure 2.16)
90
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking RDREC CSECT READ RECORD INTO BUFFER 120 . EXTREF BUFFER,LENGTH,BUFEND CLEAR X B410 CLEAR A B400 CLEAR S B440 LDT MAXLEN F RLOOP TD INPUT E3201B C JEQ RLOOP 332FFA F RD INPUT DB2015 COMPR A,S A004 JEQ EXIT STCH BUFFER,X B TIXR T B850 D JLT RLOOP 3B2FE9 EXIT +STX LENGTH RSUB 4F0000 INPUT BYTE X’F1’ F1 MAXLEN WORD BUFEND – BUFFER
91
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking WRREC CSECT 195 . WRITE RECORD FROM BUFFER 205 . EXTREF LENGTH,BUFFER CLEAR X B410 LDT LENGTH WLOOP TD =X’05’ E32012 JEQ WLOOP 332FFA C +LDCH BUFFER,X WD =X’05’ DF2008 TIXR T B850 JLT WLOOP 3B2FEF RSUB 4F0000 END FIRST 001B * =X’05’ 05
92
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking External Definition and References External definition EXTDEF name [, name] Declare symbols that are defined in this control section and used by other sections External reference EXTREF name [,name] Declare symbols that are used in this control section and are defined elsewhere For EXTREF labels, assembler has no idea where the corresponding control section will be loaded use 0 CLOOP +JSUB RDREC B100000 STCH BUFFER,X MAXLEN WORD BUFEND-BUFFER
93
ADHIPARASAKTHI ENGINEERING COLLEGE
CN-MC1701 MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking Implementation Assembler must include information in object program that will cause loader to insert proper values where required Define record Col. 1 D Col. 2-7 Name of external symbol defined in this control section Col Relative address within this control section (hex) Col Repeat info in Col for other external symbols Refer record Col. 1 R Col. 2-7 Name of external symbol referred to in this section Col Name of other external reference symbols
94
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking Modification Record Modification record Col. 1 M Col. 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 External symbol whose value is to be added to or subtracted from the indicated field Note: control section name is automatically an external symbol, i.e. it is available for use in Modification records. Example Figure 2.17 M RDREC M COPY
95
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking Figure 2.17 (1/2) H COPY D BUFFER BUFEND LENGTH 00002D R RDREC WRREC T D B B T 00001D 0D F200A 4B E2000 T F46 M RDREC M WRREC M WRREC E
96
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking Figure 2.17 (2/2) H RDREC B R BUFFER LENGTH BUFEND T D B410 B400 B F E3201B 332FFA DB T 00001D 0E 3B2FE F0000 F M BUFFER M LENGTH M BUFEND M BUFFER E H WRREC C R LENGTH BUFFER T C B E FFA DF M LENGTH M 00000D 05+BUFFER 190 MAXLEN WORD BUFEND - BUFFER
97
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Machine-Independent Assembler Features – Control section and Program Linking External Reference in Expressions Earlier definitions Required all of the relative terms be paired in an expression (an absolute expression), or that all except one be paired (a relative expression) New restriction Both terms in each pair must be relative within the same control section Ex: BUFEND-BUFFER Ex: RDREC-COPY In general, assembler cannot determine whether or not the expression is legal at assembly time. This work will be handled by a linking loader.
98
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications sps ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Main problem Forward references Data items Labels on instructions Solution Data items: require all such areas be defined before they are referenced Labels on instructions: no good solution
99
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Two types of one-pass assembler Type 1: Load-and-go Produces object code directly in memory for immediate execution Type 2: Produces usual kind of object code for later execution
100
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Load-and-Go Assembler Characteristics Useful for program development and testing Avoids the overhead of writing the object program out and reading it back Both one-pass and two-pass assemblers can be designed as load-and-go However one-pass also avoids the overhead of an additional pass over the source program For a load-and-go assembler, the actual address must be known at assembly time, we can use an absolute program
101
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Load-and-Go Assembler Assembler operations: 1. Omit address translation for any undefined symbol 2. Insert the symbol into SYMTAB, mark it undefined 3. The address that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry 4. When the definition for a symbol is encountered, the proper address for the symbol is then inserted into any instructions previously generated according to the forward reference list
102
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 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 symbols Search SYMTAB for the symbol named in the END statement and jump to this location to begin execution The actual starting address must be specified at assembly time
103
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.18 Line Loc Source statement Object code COPY START 1000 EOF BYTE C’EOF’ 454F46 THREE WORD ZERO WORD RETADR RESW 1 5 100C LENGTH RESW 1 6 100F BUFFER RESB 4096 10 200F FIRST STL RETADR CLOOP JSUB RDREC 48203D LDA LENGTH 00100C COMP ZERO 30 201B JEQ ENDFIL 35 201E JSUB WRREC J CLOOP 3C2012 ENDFIL LDA EOF STA BUFFER 0C100F 55 202A LDA THREE 60 202D STA LENGTH 0C100C JSUB WRREC LDL RETADR RSUB 4C0000
104
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19(a) – Before Line 40 Memory Address Contents F xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 C C2012 Address unknown yet
105
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19(a) - SYMTAB Symbol Value 2013 201F 201C LENGTH 100C RDREC * THREE 1003 ZERO 1006 WRREC EOF 1000 ENDFIL RETADR 1009 BUFFER 100F CLOOP 2012 FIRST 200F ...
106
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19(a) – After Line 45 Memory Address Contents F xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 C C
107
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19(a) - SYMTAB Symbol Value LENGTH 100C RDREC * THREE 1003 ZERO 1006 WRREC EOF 1000 ENDFIL 2024 RETADR 1009 BUFFER 100F CLOOP 2012 FIRST 200F ... 2013 201F
108
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.18 110 . SUB TO READ RECORD INTO BUFFER 120 . INPUT BYTE X’F1’ F1 A MAXLEN WORD 124 . D RDREC LDX ZERO LDA ZERO RLOOP TD INPUT E02039 JEQ RLOOP RD INPUT D82039 C COMP ZERO F JEQ EXIT 30205B STCH BUFFER,X 54900F TIX MAXLEN 2C203A JLT RLOOP B EXIT STX LENGTH 10100C E RSUB 4C0000
109
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19 (b) – After Line 160 Memory Address Contents F xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 D00100C C C 100F C100C C00 00F E DB F
110
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.19 (b) – After Line 160 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
111
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Program for one pass assembler – Fig 2.18 195 . SUB TO WRITE RECORD FROM BUFFER 205 . OUTPUT BYTE X’05’ 05 207 . WRREC LDX ZERO WLOOP TD OUTPUT E02061 JEQ WLOOP B LDCH BUFFER,X 50900F E WD OUTPUT DC2061 TIX LENGTH 2C100C JLT WLOOP RSUB 4C0000 END FIRST
112
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Type 2 Assembler Will produce object code Assembler operations: Forward references are entered into list as before Instruction referencing are written into object file as a Text record, even with incorrect addresses When definition of a symbol is encountered, assembler must generate another Text record with the correct operand address Loader is used to insert correct addresses into instructions with forward references that could not be handled by the assembler Object program records must be kept in original order when they are presented to the loader
113
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Type 2 Assembler – Fig 2.20 (Partial) H COPY A T F T 00200F C C2012 T 00201C T C100F C100C C0000 T D … E 00200F
114
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – One Pass Assembler Type 2 Assembler – Fig. 2.20
115
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Restriction on EQU and ORG No forward reference, since symbols’ value can’t be defined during the first pass Example: ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1 Assemblers with 2 passes cannot resolve
116
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Resolve forward references with as many passes as needed Portions that involve forward references in symbol definition are saved during Pass 1 Additional passes through stored definitions Finally a normal Pass 2 Example implementation: Use link lists to keep track of whose value depend on an undefined symbol
117
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Fig (a) – After Pass 1 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 * HALFSZ 1 symbol undefined
118
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Fig (c) – MAXLEN defined 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 HALFSZ MAXLEN
119
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Fig (c) – MAXLEN defined 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 HALFSZ MAXLEN
120
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Fig (d) – PERVBT defined 1 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 BUFFER-1 MAXLEN &2 BUFEND-BUFFER BUFFER MAXLEN HALFSZ MAXLEN PREVBT
121
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur 2.4.2 Assembler Design Options – Multi Pass Assembler Fig (e) – After Line 4 1 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 BUFEND-BUFFER BUFFER 1034 MAXLEN HALFSZ Assume loc=1034
122
ADHIPARASAKTHI ENGINEERING COLLEGE
MC9224- System Software Department of Computer Applications ponns ADHIPARASAKTHI ENGINEERING COLLEGE OmSakthi Melmaruvathur Assembler Design Options – Multi Pass Assembler Fig (f) – After Line 5 BUFEND 2034 HLFSZ 800 PREVBT 1033 MAXLEN 1000 BUFFER 1034 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER-1 ... 4 BUFFER RESB 4096 5 BUFEND EQU *
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.