Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2422 Assembly Language & System Programming December 7, 2006.

Similar presentations


Presentation on theme: "CS2422 Assembly Language & System Programming December 7, 2006."— Presentation transcript:

1 CS2422 Assembly Language & System Programming December 7, 2006

2 Today’s Topic Assembler: Machine Dependent Features –SIC/XE –Program Relocation –Modification Records in an Object File.

3 Study Guide Sections 2.2 (especially 2.2.2) of Beck’s “System Software” book. –Section 2.2: Program Relocation

4 SIC/XE Assembler We have learned the 2-pass assembler for SIC. What’s new for SIC/XE? –More addressing modes. –Program Relocation.

5 An SIC/XE Example (Figure 2.6) LineLoc Source statementObject code 50000COPY START 0 100000FIRST STL RETADR17202D 120003 LDB #LENGTH69202D 13 BASE LENGTH 150006CLOOP+JSUB RDREC4B101036 20000A LDA LENGTH032026 25000D COMP#0290000 300010 JEQ ENDFIL332007 350013+JSUB WRREC4B10105D 400017 J CLOOP3F2FEC 45001AENDFIL LDA EOF032010 50001D STA BUFFER0F2016 550020 LDA#3010003 600023 STA LENGTH0F200D 650026+JSUB WRREC4B10105D 70002A J@RETADR3E2003 80002DEOF BYTE C’EOF’454F46 950030RETADR RESW 1 1000033LENGTH RESW 1 1050036BUFFER RESB 4096

6 115.READ RECORD INTO BUFFER 120. 1251036RDREC CLEAR XB410 1301038 CLEAR AB400 132103A CLEAR SB440 133103C+LDT#409675101000 1351040RLOOP TD INPUTE32019 1401043 JEQ RLOOP332FFA 1451046 RD INPUT DB2013 1501049 COMPR A,SA004 155104B JEQ EXIT332008 160104E STCH BUFFER,X57C003 1651051 TIXR TB850 1701053 JLT RLOOP3B2FEA 1751056EXIT STX LENGTH134000 1801059 RSUB4F0000 185105CINPUT BYTE X’F1’F1 195. 200.WRITE RECORD FROM BUFFER 205. 210105DWRREC CLEAR XB410 212105F LDT LENGTH774000 2151062WLOOP TD OUTPUTE32011 2201065 JEQ WLOOP332FFA 2251068 LDCH BUFFER,X53C003 230106B WD OUTPUTDF2008 235106E TIXR TB850...(omitted)

7 A Case of Object Code Generation Figure 2.6, Line 10 STLRETADR  17 20 2D The mode bit p=1, meaning PC relative addressing mode. OPCODEeAddress 6 bits12 bits nixbp 0001 0100000 0010 110111001 172D20

8 Instruction Format and Addressing Mode SIC/XE –PC-relative or Base-relative addressing: op m –Indirect addressing: op @m –Immediate addressing: op #c –Extended format: +op m –Index addressing: op m,x –register-to-register instructions –larger memory -> multi-programming (program allocation)

9 Translation Register translation –Register name (A, X, L, B, S, T, F, PC, SW) and their values (0,1, 2, 3, 4, 5, 6, 8, 9) –Preloaded in SYMTAB Address translation –Most register-memory instructions use program counter relative or base relative addressing –Format 3: 12-bit address field Base-relative: 0~4095 PC-relative: -2048~2047 –Format 4: 20-bit address field

10 PC-Relative Addressing Mode PC-relative –100000FIRSTSTLRETADR17202D Displacement= RETADR - PC = 30-3 = 2D –400017JCLOOP3F2FEC Displacement= CLOOP-PC= 6 - 1A= -14= FEC OPCODEeAddressnixbp 0001 010(02D) 16 11001 OPCODEeAddressnixbp 0011 110(FEC) 16 11001

11 Base-Relative Addressing Modes Base-relative –Base register is under the control of the programmer –12LDB#LENGTH –13BASELENGTH –160104ESTCHBUFFER, X57C003 Displacement= BUFFER - B = 0036 - 0033 = 3 –NOBASE is used to inform the assembler that the contents of the base register no longer be relied upon for addressing OPCODEeAddressnixbp 0101 010(003) 16 11110

12 Immediate Address Translation (1/2) Immediate addressing –550020LDA#3010003 –133103C +LDT#409675101000 OPCODEeAddressnixbp 0000 000(003) 16 01000 OPCODEeAddressnixbp 0111 011(01000) 16 01000

13 Immediate Address Translation (2/2) Immediate addressing –120003LDB#LENGTH69202D –120003LDB#LENGTH690033 The immediate operand is the symbol LENGTH The address of this symbol LENGTH is loaded into register B LENGTH=0033=PC+displacement=0006+02D If immediate mode is specified, the target address becomes the operand OPCODEeAddressnixbp 0110 100(02D) 16 01001 OPCODEeAddressnixbp 0110 100(033) 16 01000

14 Indirect Address Translation Indirect addressing –Target addressing is computed as usual (PC- relative or BASE-relative) –Only the n bit is set to 1 –70002AJ@RETADR3E2003 TA=RETADR=0030 TA=(PC)+disp=002D+0003 OPCODEeAddressnixbp 0011 110(003) 16 10001

15 Program Relocation

16 Examples of Program Relocation (1/2) Example Fig. 2.2 –Absolute program, starting address 1000 520001000COPYSTART1000 1020001000FIRSTSTLRETADR141033 142033 1520031003CLOOPJSUBRDREC482039 483039 2020061006LDALENGTH001036 002036 2520091009COMPZERO281030 282030 30200C100CJEQENDFIL301015 302015 35200F100FJSUBWREC482061 483061 4020121012JCLOOP3C1003 3C2003 4520151015ENDFILLDAEOF00102A 00202A 5020181018STABUFFER0C1039 0C2039 55201B101BLDATHREE00102D 00202D 60201E101ESTALENGTH0C1036 0C2036 6520211021JSUBWREC482061 483061 7020241024LDLRETADR081033 082033 7520271027RSUB4C0000 4C0000 80202A102AEOFBYTEC'EOF'454E46 454E46 85202D102DTHREEWORD3000003 000003 9020301030ZEROWORD0000000 000000 9520331033RETADRRESW1 10020361036LENGTHRESW1 10520391039BUFFERRESB4096

17 Examples of Program Relocation (1/2) Example Fig. 2.2 –Absolute program, starting address 1000 520001000COPYSTART1000 1020001000FIRSTSTLRETADR141033 142033 1520031003CLOOPJSUBRDREC482039 483039 2020061006LDALENGTH001036 002036 2520091009COMPZERO281030 282030 30200C100CJEQENDFIL301015 302015 35200F100FJSUBWREC482061 483061 4020121012JCLOOP3C1003 3C2003 4520151015ENDFILLDAEOF00102A 00202A 5020181018STABUFFER0C1039 0C2039 55201B101BLDATHREE00102D 00202D 60201E101ESTALENGTH0C1036 0C2036 6520211021JSUBWREC482061 483061 7020241024LDLRETADR081033 082033 7520271027RSUB4C0000 4C0000 80202A102AEOFBYTEC'EOF'454E46 454E46 85202D102DTHREEWORD3000003 000003 9020301030ZEROWORD0000000 000000 9520331033RETADRRESW1 10020361036LENGTHRESW1 10520391039BUFFERRESB4096 ====  2000

18 Examples of Program Relocation (2/2) Example Fig. 2.6: –Except for absolute address, the rest of the instructions need not be modified not a memory address (immediate addressing) PC-relative, Base-relative –The only parts of the program that require modification at load time are those that specify direct addresses 51000 0000COPY START 0 101000 0000FIRST STL RETADR17202D 17202D 121003 0003 LDB#LENGTH69202D 69202D 13 BASE LENGTH 151006 0006CLOOP+JSUB RDREC4B101036 4B102036 20100A 000A LDA LENGTH032026 032026 25100D 000D COMP#0290000 290000 301010 0010 JEQ ENDFIL332007 332007 351013 0013+JSUB WRREC4B10105D 4B10205D 401017 0017 J CLOOP3F2FEC 3F2FEC 45101A 001AENDFIL LDA EOF032010 032010 50101D 001D STA BUFFER0F2016 0F2016 551020 0020 LDA#3010003 010003 601023 0023 STA LENGTH0F200D 0F200D 651026 0026+JSUB WRREC4B10105D 4B10205D 70102A 002A J@RETADR3E2003 3E2003 80102D 002DEOF BYTE C'EOF'454F46 454F46 951030 0030RETADR RESW 1 1001036 0036BUFFER RESB 4096

19 Examples of Program Relocation (2/2) Example Fig. 2.6: –Except for absolute address, the rest of the instructions need not be modified not a memory address (immediate addressing) PC-relative, Base-relative –The only parts of the program that require modification at load time are those that specify direct addresses 51000 0000COPY START 0 101000 0000FIRST STL RETADR17202D 17202D 121003 0003 LDB#LENGTH69202D 69202D 13 BASE LENGTH 151006 0006CLOOP+JSUB RDREC4B101036 4B102036 20100A 000A LDA LENGTH032026 032026 25100D 000D COMP#0290000 290000 301010 0010 JEQ ENDFIL332007 332007 351013 0013+JSUB WRREC4B10105D 4B10205D 401017 0017 J CLOOP3F2FEC 3F2FEC 45101A 001AENDFIL LDA EOF032010 032010 50101D 001D STA BUFFER0F2016 0F2016 551020 0020 LDA#3010003 010003 601023 0023 STA LENGTH0F200D 0F200D 651026 0026+JSUB WRREC4B10105D 4B10205D 70102A 002A J@RETADR3E2003 3E2003 80102D 002DEOF BYTE C'EOF'454F46 454F46 951030 0030RETADR RESW 1 1001036 0036BUFFER RESB 4096 ==  1000

20 How to Make Program Relocation Easier Use program-counter (PC) 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. Virtual memory! (Not covered in this course)

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

22 Object File with M-Records Modification records are added to the object files. (See pp.64-65 and Figure 2.8.) Example: HCOPY 001000 001077 T000000 1D 17202D…4B101036… T00001D …… … M000007 05  Modification Record …… E000000

23 Object Code


Download ppt "CS2422 Assembly Language & System Programming December 7, 2006."

Similar presentations


Ads by Google