1 / 122

Unit – II Assembler

OmSakthi. ADHIPARASAKTHI ENGINEERING COLLEGE. Melmaruvathur-603 319. Unit – II Assembler. Department of Computer Applications. ponns. MC9224 – System Software. OmSakthi. ADHIPARASAKTHI ENGINEERING COLLEGE. Melmaruvathur-603 319. Outline Basic Assembler Functions

ciaran-wolf
Download Presentation

Unit – II Assembler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 Unit – II Assembler Department of Computer Applications ponns MC9224 – System Software

  2. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 • 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 Department of Computer Applications ponns MC9224- System Software

  3. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 Department of Computer Applications ponns MC9224- System Software

  4. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 4096 4096-BYTE BUFFER AREA Department of Computer Applications ponns MC9224- System Software

  5. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 Department of Computer Applications ponns MC9224- System Software

  6. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 Department of Computer Applications ponns MC9224- System Software

  7. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 dataarea Department of Computer Applications ponns MC9224- System Software

  8. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 Department of Computer Applications ponns MC9224- System Software

  9. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. A Simple SIC Assembler – Example Program & Object Code Line Loc Source statement Object code 5 1000 COPY START 1000 10 1000 FIRST STL RETADR 141033 15 1003 CLOOP JSUB RDREC 482039 20 1006 LDA LENGTH 001036 25 1009 COMP ZERO 281030 30 100C JEQ ENDFIL 301015 35 100F JSUB WRREC 482061 40 1012 J CLOOP 3C1003 45 1015 ENDFIL LDA EOF 00102A 50 1018 STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 65 1021 JSUB WRREC 482061 70 1024 LDL RETADR 081033 75 1027 RSUB 4C0000 Department of Computer Applications ponns MC9224- System Software

  10. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 3 000003 90 1030 ZERO WORD 0 000000 95 1033 RETADR RESW 1 100 1036 LENGTH RESW 1 105 1039 BUFFER RESB 4096 Department of Computer Applications ponns MC9224- System Software

  11. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. A Simple SIC Assembler – Example Program & Object Code 110 . 115 .SUB TO READ RECORD INTO BUFFER 120 . 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203F 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A RSUB 4C0000 185 205D INPUT BYTE X’F1’ F1 190 205E MAXLEN WORD 4096 001000 Department of Computer Applications ponns MC9224- System Software

  12. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. A Simple SIC Assembler – Example Program & Object Code 195 . 200 . SUB TO WRITE RECORD FROM BUFFER 205 . 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER,X 509039 230 206D WD OUTPUT DC2079 235 2070 TIX LENGTH 2C1036 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X’05’ 05 255 END FIRST Department of Computer Applications ponns MC9224- System Software

  13. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. A Simple SIC Assembler • Mnemonic code (or instruction name)  opcode • Examples: STL 1033  14 10 33 LDA 1036  00 10 36 0001 0100 0 001 0000 0011 0011 0000 0000 0 001 0000 0011 0110 Department of Computer Applications ponns MC9224- System Software

  14. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 LocLabelOperatorOperand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … … … … … 1012 J CLOOP … … … … … 1033 RETADR RESW 1 Department of Computer Applications ponns MC9224- System Software

  15. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 Department of Computer Applications ponns MC9224- System Software

  16. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 Department of Computer Applications ponns MC9224- System Software

  17. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. A Simple SIC Assembler – Record Types • Object Program contains three Records • Header Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col. 14-19 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 (69-10+1)/6=10 instructions • End Col.1 E Col.2~7 Address of first executable instruction (hex) Department of Computer Applications ponns MC9224- System Software

  18. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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^001000 starting address Department of Computer Applications ponns MC9224- System Software

  19. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.1. 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 Department of Computer Applications ponns MC9224- System Software

  20. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE 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) Source program Intermediate file Object code Pass 1 Pass 2 OPTAB SYMTAB SYMTAB Department of Computer Applications ponns MC9224- System Software

  21. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. 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 opcodesinto machine language Department of Computer Applications ponns MC9224- System Software

  22. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. 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 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039 Department of Computer Applications ponns MC9224- System Software

  23. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE 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 two passes. • Pass 1 writes an intermediate file • Each source statement together with its assigned address • Error indicators • Used as input for pass 2 Department of Computer Applications ponns MC9224- System Software

  24. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler Department of Computer Applications ponns MC9224- System Software

  25. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass1 Assembler Department of Computer Applications ponns MC9224- System Software

  26. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler Department of Computer Applications ponns MC9224- System Software

  27. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.1.2. Assembler Algorithm and Data Structures Algorithm for Pass2 Assembler Department of Computer Applications ponns MC9224- System Software

  28. OmSakthi RESW 1 RESW 1 0 WORD 0 3 WORD 3 ‘E’ ‘O’ ‘F’ BYTE C’EOF’ RSUB LDL RETADR JEQ ENDFIL COMP ZERO LDA LENGTH JSUB RDREC STL RETADR 1036 xxxxxx ADHIPARASAKTHI ENGINEERING COLLEGE 1033 xxxxxx Melmaruvathur-603 319 1030 000000 2.1.2. Assembler Algorithm and Data Structures Object Program Loading 102D 000003 102A 454F46 LENGTH 1027 4C0000 RETADR 1024 081033 … 100C 301015 1009 281030 1006 001036 1003 482039 1000 141033 … Department of Computer Applications ponns MC9224- System Software

  29. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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 Department of Computer Applications ponns MC9224- System Software

  30. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes • SIC/XE: • PC-relative or base-relative addressing: op m • Indirect addressing: op @m • Immediate addressing: op #c • Extended format: +op m • Index addressing: op m,x • Register-to-register instructions • Larger memory  multi-programming (program allocation) Department of Computer Applications ponns MC9224- System Software

  31. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. 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~4095 PC-relative: -2048~2047 • Format 4: 20-bit address field Department of Computer Applications ponns MC9224- System Software

  32. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes Line Loc Source statement Object code 5 0000 COPY START 0 10 0000 FIRST STL RETADR 17202D 12 0003 LDB #LENGTH 69202D 13 BASE LENGTH 15 0006 CLOOP +JSUB RDREC 4B101036 20 000A LDA LENGTH 032026 25 000D COMP #0 290000 30 0010 JEQ ENDFIL 332007 35 0013 +JSUB WRREC 4B10105D 40 0017 J CLOOP 3F2FEC 45 001A ENDFIL LDA EOF 032010 50 001D STA BUFFER 0F2016 55 0020 LDA #3 010003 60 0023 STA LENGTH 0F200D 65 0026 +JSUB WRREC 4B10105D 70 002A J @RETADR 3E2003 80 002D EOF BYTE C’EOF’ 454F46 95 0030 RETADR RESW 1 100 0033 LENGTH RESW 1 105 0036 BUFFER RESB 4096 Department of Computer Applications ponns MC9224- System Software

  33. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes 115 . READ RECORD INTO BUFFER 120 . 125 1036 RDREC CLEAR X B410 130 1038 CLEAR A B400 132 103A CLEAR S B440 133 103C +LDT #4096 75101000 135 1040 RLOOP TD INPUT E32019 140 1043 JEQ RLOOP 332FFA 145 1046 RD INPUT DB2013 150 1049 COMPR A,S A004 155 104B JEQ EXIT 332008 160 104E STCH BUFFER,X 57C003 165 1051 TIXR T B850 170 1053 JLT RLOOP 3B2FEA 175 1056 EXIT STX LENGTH 134000 180 1059 RSUB 4F0000 185 105C INPUT BYTE X’F1’ F1 Department of Computer Applications ponns MC9224- System Software

  34. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes 195 . 200 . WRITE RECORD FROM BUFFER 205 . 210 105D WRREC CLEAR X B410 12 105F LDT LENGTH 774000 215 1062 WLOOP TD OUTPUT E32011 220 1065 JEQWLOOP 332FFA 225 1068 LDCHBUFFER,X 53C003 230 106B WD OUTPUT DF2008 235 106E TIXR T B850 240 1070 JLTWLOOP 3B2FEF 245 1073 RSUB 4F0000 250 1076 OUTPUT BYTE X’05’ 05 255 END FIRST Department of Computer Applications ponns MC9224- System Software

  35. OmSakthi OPCODE OPCODE n n i i x x b b p p e e Address Address 0011 11 0001 01 1 1 1 1 0 0 0 0 1 1 0 0 (02D)16 (FEC)16 ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes PC Relative Addressing • 10 0000 FIRST STLRETADR 17202D • Displacement= RETADRPC = 00300003 = 02D • 40 0017 J CLOOP 3F2FEC • Displacement= CLOOPPC= 0006001A= 14= FEC Department of Computer Applications ponns MC9224- System Software

  36. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. 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 160 104E STCH BUFFER, X 57C003 • Displacement= BUFFERB = 00360033 = 3 • Compare lines 20 and 175 (PC vs Base addressing) OPCODE n i x b p e Address 0101 01 1 1 1 1 0 0 (003)16 Department of Computer Applications ponns MC9224- System Software

  37. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE 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 cannot be changeable • Base register is under the control of programmer, and set initially and changeable Department of Computer Applications ponns MC9224- System Software

  38. OmSakthi OPCODE OPCODE n n i i x x b b p p e e Address Address 0000 00 0111 01 0 0 1 1 0 0 0 0 0 0 1 0 (01000)16 (003)16 ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes Immediate Address Translation 55 0020 LDA #3 010003 133 103C +LDT #4096 75101000 Department of Computer Applications ponns MC9224- System Software

  39. OmSakthi OPCODE OPCODE n n i i x x b b p p e e Address Address 0110 10 0110 10 0 0 1 1 0 0 0 0 0 1 0 0 (02D)16 (033)16 ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. Instruction Formats and Addressing Modes Immediate Address Translation 12 0003 LDB #LENGTH 69202D 12 0003 LDB #LENGTH 690033 • The immediate operand is the value of the symbol LENGTH, which is the address assigned to LENGTH • LENGTH=0033=PC+displacement=0006+02D Department of Computer Applications ponns MC9224- System Software

  40. OmSakthi OPCODE n i x b p e Address 0011 11 1 0 0 0 1 0 (003)16 ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.1. 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 J @RETADR 3E2003 • TA=RETADR=0030 • TA=(PC)+displacement=002D+0003 Department of Computer Applications ponns MC9224- System Software

  41. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. 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. Department of Computer Applications ponns MC9224- System Software

  42. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. Program Relocation Loaded at 0000 Loaded at 7420 Loaded at 5000 Department of Computer Applications ponns MC9224- System Software

  43. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. Program Relocation • Example Fig. 2.2 • Absolute program, starting address 1000 ====  2000 ====  2000 5 2000 1000 COPY START 1000 10 2000 1000 FIRST STL RETADR 141033 142033 15 2003 1003 CLOOP JSUB RDREC 482039 483039 20 2006 1006 LDA LENGTH 001036 002036 25 2009 1009 COMP ZERO 281030 282030 30 200C 100C JEQ ENDFIL 301015 302015 35 200F 100F JSUB WREC 482061 483061 40 2012 1012 J CLOOP 3C1003 3C2003 45 2015 1015 ENDFIL LDA EOF 00102A 00202A 50 2018 1018 STA BUFFER 0C1039 0C2039 55 201B 101B LDA THREE 00102D 00202D 60 201E 101E STA LENGTH 0C1036 0C2036 65 2021 1021 JSUB WREC 482061 483061 70 2024 1024 LDL RETADR 081033 082033 75 2027 1027 RSUB 4C0000 4C0000 80 202A 102A EOF BYTE C'EOF' 454E46 454E46 85 202D 102D THREE WORD 3 000003 000003 90 2030 1030 ZERO WORD 0 000000 000000 95 2033 1033 RETADR RESW 1 100 2036 1036 LENGTH RESW 1 105 2039 1039 BUFFER RESB 4096 Department of Computer Applications ponns MC9224- System Software

  44. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. 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 5 1000 0000 COPY START 0 10 1000 0000 FIRST STL RETADR 17202D 17202D 12 1003 0003 LDB #LENGTH 69202D 69202D 13 BASE LENGTH 15 1006 0006 CLOOP +JSUB RDREC 4B101036 4B102036 20 100A 000A LDA LENGTH 032026 032026 25 100D 000D COMP #0 290000 290000 30 1010 0010 JEQ ENDFIL 332007 332007 35 1013 0013 +JSUB WRREC 4B10105D 4B10205D 40 1017 0017 J CLOOP 3F2FEC 3F2FEC 45 101A 001A ENDFIL LDA EOF 032010 032010 50 101D 001D STA BUFFER 0F2016 0F2016 55 1020 0020 LDA #3 010003 010003 60 1023 0023 STA LENGTH 0F200D 0F200D 65 1026 0026 +JSUB WRREC 4B10105D 4B10205D 70 102A 002A J @RETADR 3E2003 3E2003 80 102D 002D EOF BYTE C'EOF' 454F46 454F46 95 1030 0030 RETADR RESW 1 100 1036 0036 BUFFER RESB 4096 ==  1000 Department of Computer Applications ponns MC9224- System Software

  45. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. 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 Department of Computer Applications ponns MC9224- System Software

  46. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. 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 8-9 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) Department of Computer Applications ponns MC9224- System Software

  47. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. Program Relocation Object File with M-Records • Modification records are added to the object files. (See pp.67 and Figure 2.8.) • Example: HCOPY 001000 001077 T000000 1D 17202D…4B101036… T00001D …… … M000007 05  Modification Record …… E000000 Department of Computer Applications ponns MC9224- System Software

  48. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. Program Relocation 0000 1 7 STL RETADR M000007 05 Modification Record 0001 2 0 0002 2 D 5 half-bytes 0003 6 9 LDB #LENGTH 0004 2 0 0005 2 D Address 0007 0006 4 B +JSUB RDREC 0007 1 0 0008 1 0 0009 3 6 000A LDA LENGTH 0 3 000B 2 0 000C 2 6 Department of Computer Applications ponns MC9224- System Software

  49. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 2.2.2. Program Relocation Object Code Department of Computer Applications ponns MC9224- System Software

  50. OmSakthi ADHIPARASAKTHI ENGINEERING COLLEGE Melmaruvathur-603 319 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) 045 001A ENDFIL LDA =C’EOF’ 215 1062 WLOOP TD =X’05’ Department of Computer Applications ponns MC9224- System Software

More Related