Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.

Similar presentations


Presentation on theme: "CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University."— Presentation transcript:

1 CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University

2 1 Today ’ s Topic  Assembler: Machine Dependent Features SIC/XE and assembler translation Program Relocation Modification Records in an Object File  Study guide: Sections 2.2 (especially 2.2.2) of Beck ’ s “ System Software ” book -- Program Relocation

3 2 SIC/XE Assembler  We have learned the 2-pass assembler for SIC  What’s new for SIC/XE? More addressing modes Program relocation

4 3 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)

5 4 Translation  Register translation Register name (A, X, L, B, S, T, F, PC, SW) translated to their ids (0,1, 2, 3, 4, 5, 6, 8, 9) 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) Format 3: 12-bit displacement ‒ Base-relative: 0~4095 PC-relative: -2048~2047 Format 4: 20-bit address field

6 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

7 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

8 7 195. 200.WRITE RECORD FROM BUFFER 205. 210105DWRREC CLEAR X B410 212105F LDT LENGTH 774000 2151062WLOOP TD OUTPUT E32011 2201065 JEQ WLOOP 332FFA 2251068 LDCH BUFFER,X 53C003 230106B WD OUTPUT DF2008 235106E TIXR T B850 2401070 JLT WLOOP 3B2FEF 2451073 RSUB 4F0000 2501076OUTPUT BYTE X’05’ 05 255 END FIRST

9 8 PC-Relative Addressing Mode 100000FIRST STLRETADR17202D ‒ Displacement= RETADR  PC = 0030  0003 = 02D 400017 JCLOOP3F2FEC ‒ Displacement= CLOOP  PC= 0006  001A=  14= FEC OPCODEeAddressnixbp 0001 010(02D) 16 11001 OPCODEeAddressnixbp 0011 110(FEC) 16 11001

10 9 Base-Relative Addressing Mode  BASE register and directive: 12LDB#LENGTH 13BASELENGTH Base register is under the control of programmer BASE directive tells assembler that LENGHTH is base address; NOBASE releases the binding 160 104ESTCHBUFFER, X57C003 ‒ Displacement= BUFFER  B = 0036  0033 = 3 ‒ Compare lines 20 and 175 (PC vs Base addressing) OPCODEeAddressnixbp 0101 010(003) 16 11110 Why cannot we use PC-relative?

11 10 Immediate Address Translation  Immediate addressing 550020LDA#3010003 133103C +LDT#409675101000 OPCODEeAddressnixbp 0000 000(003) 16 01000 OPCODEeAddressnixbp 0111 011(01000) 16 01000

12 11 Immediate Address Translation 120003LDB#LENGTH69202D 120003LDB#LENGTH690033  The immediate operand is the value of the symbol LENGTH, which is the address assigned to LENGTH  LENGTH=0033=PC+displacement=0006+02D OPCODEeAddressnixbp 0110 100(02D) 16 01001 OPCODEeAddressnixbp 0110 100(033) 16 01000

13 12 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)+displacement=002D+0003 OPCODEeAddressnixbp 0011 110(003) 16 10001

14 13 Today ’ s Topic  Assembler: Machine Dependent Features SIC/XE and assembler translation Program Relocation Modification Records in an Object File

15 14 Program Relocation Loaded at 0000 Loaded at 5000 Loaded at 7420

16 Example 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

17 Example of Program Relocation (2/2)  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 ==  100051000 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

18 17 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.  Virtual memory! (not covered in this course)  The sample SIC/EX program is easier Mostly PC or base relative Only extended format instructions have direct addresses and require modification

19 18 Relocatable Program  An object program that contains information needed for address modification for loading  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 (address field to be modified may not occupy an integral number of bytes, e.g. 20 bits)

20 19 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

21 20 Modification Record 0009 3 6 1 0 4 B 2 D 0008 0007 0006 0005 +JSUB RDREC 0004 2 0 6 9 2 D 2 0 1 7 0003 0002 0001 0000 LDB#LENGTH STLRETADR 000C 2 6 2 0 0 3 000B 000A LDALENGTH M000007 05 Address 0007 5 half-bytes

22 21 Object Code


Download ppt "CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University."

Similar presentations


Ads by Google