CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University
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
2 SIC/XE Assembler We have learned the 2-pass assembler for SIC What’s new for SIC/XE? More addressing modes Program relocation
3 Instruction Format and Addressing Mode 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)
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
5 An SIC/XE Example (Figure 2.6) LineLoc Source statementObject code 50000COPY START FIRST STL RETADR17202D LDB #LENGTH69202D 13 BASE LENGTH CLOOP+JSUB RDREC4B A LDA LENGTH D COMP# JEQ ENDFIL JSUB WRREC4B10105D J CLOOP3F2FEC 45001AENDFIL LDA EOF D STA BUFFER0F LDA# STA LENGTH0F200D JSUB WRREC4B10105D 70002A 80002DEOF BYTE C’EOF’454F RETADR RESW LENGTH RESW BUFFER RESB 4096
6 115.READ RECORD INTO BUFFER RDREC CLEAR XB CLEAR AB A CLEAR SB C+LDT # RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB COMPR A,SA B JEQ EXIT E STCH BUFFER,X57C TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH RSUB4F CINPUT BYTE X’F1’F1
WRITE RECORD FROM BUFFER DWRREC CLEAR X B F LDT LENGTH WLOOP TD OUTPUT E JEQ WLOOP 332FFA LDCH BUFFER,X 53C B WD OUTPUT DF E TIXR T B JLT WLOOP 3B2FEF RSUB 4F OUTPUT BYTE X’05’ END FIRST
8 PC-Relative Addressing Mode FIRST STLRETADR17202D ‒ Displacement= RETADR PC = 0030 0003 = 02D JCLOOP3F2FEC ‒ Displacement= CLOOP PC= 0006 001A= 14= FEC OPCODEeAddressnixbp (02D) OPCODEeAddressnixbp (FEC)
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 ESTCHBUFFER, X57C003 ‒ Displacement= BUFFER B = 0036 0033 = 3 ‒ Compare lines 20 and 175 (PC vs Base addressing) OPCODEeAddressnixbp (003) Why cannot we use PC-relative?
10 Immediate Address Translation Immediate addressing LDA# C +LDT# OPCODEeAddressnixbp (003) OPCODEeAddressnixbp (01000)
11 Immediate Address Translation LDB#LENGTH69202D LDB#LENGTH The immediate operand is the value of the symbol LENGTH, which is the address assigned to LENGTH LENGTH=0033=PC+displacement= D OPCODEeAddressnixbp (02D) OPCODEeAddressnixbp (033)
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 ‒ TA=RETADR=0030 ‒ TA=(PC)+displacement=002D+0003 OPCODEeAddressnixbp (003)
13 Today ’ s Topic Assembler: Machine Dependent Features SIC/XE and assembler translation Program Relocation Modification Records in an Object File
14 Program Relocation Loaded at 0000 Loaded at 5000 Loaded at 7420
Example of Program Relocation (1/2) Example Fig. 2.2 Absolute program, starting address COPYSTART FIRSTSTLRETADR CLOOPJSUBRDREC LDALENGTH COMPZERO C100CJEQENDFIL F100FJSUBWREC JCLOOP3C1003 3C ENDFILLDAEOF00102A 00202A STABUFFER0C1039 0C B101BLDATHREE00102D 00202D 60201E101ESTALENGTH0C1036 0C JSUBWREC LDLRETADR RSUB4C0000 4C A102AEOFBYTEC'EOF'454E46 454E D102DTHREEWORD ZEROWORD RETADRRESW LENGTHRESW BUFFERRESB4096 ==== 2000
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 == COPY START FIRST STL RETADR17202D 17202D LDB#LENGTH69202D 69202D 13 BASE LENGTH CLOOP+JSUB RDREC4B B A 000A LDA LENGTH D 000D COMP# JEQ ENDFIL JSUB WRREC4B10105D 4B10205D J CLOOP3F2FEC 3F2FEC 45101A 001AENDFIL LDA EOF D 001D STA BUFFER0F2016 0F LDA# STA LENGTH0F200D 0F200D JSUB WRREC4B10105D 4B10205D 70102A 002A 3E D 002DEOF BYTE C'EOF'454F46 454F RETADR RESW BUFFER RESB 4096
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
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)
19 Object File with M-Records Modification records are added to the object files. (See pp and Figure 2.8.) Example: HCOPY T D 17202D…4B101036… T00001D …… … M Modification Record …… E000000
20 Modification Record B 2 D JSUB RDREC D LDB#LENGTH STLRETADR 000C B 000A LDALENGTH M Address half-bytes
21 Object Code