Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.

Similar presentations


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

1 CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University

2 1 Today ’ s Topic  Beck ’ s Section 2.4: Assembler Design Options One-pass assemblers Multi-pass assemblers

3 2 One-Pass Assemblers (1/2)  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

4 3 One-Pass Assemblers (2/2)  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

5 4 Load-and-go Assembler (1/3)  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

6 5 Load-and-go Assembler (2/3)  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

7 6 Load-and-go Assembler (3/3)  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

8 7 Program for One-pass Assembler LineLoc Source statementObject code 01000COPYSTART1000 11000EOFBYTEC’EOF’454F46 21003THREEWORD3000003 31006ZEROWORD0000000 41009RETADRRESW1 5100CLENGTHRESW1 6100FBUFFERRESB4096 10200FFIRSTSTLRETADR141009 152012CLOOPJSUBRDREC48203D 202015LDALENGTH00100C 252018COMPZERO281006 30201BJEQENDFIL302024 35201EJSUBWRREC482062 402021JCLOOP3C2012 452024ENDFILLDAEOF001000 502027STABUFFER0C100F 55202ALDATHREE001003 60202DSTALENGTH0C100C 652030JSUBWRREC482062 702033LDLRETADR081009 752036RSUB4C0000 Figure 2.18

9 8 Figure 2.19(a): Before Line 40 Memory AddressContents 1000454F4600 00030000 00xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 2010100948-- --00100C 28100630 ----48-- 2020--3C2012. Address unknown yet

10 9 Figure 2.19(a): Before Line 40  SYMTAB: LENGTH100C RDREC* THREE1003 ZERO1006 WRREC* EOF1000 ENDFIL* RETADR1009 BUFFER100F CLOOP2012 FIRST200F... SymbolValue 2013  201F  201C 

11 10 After Line 45 Memory AddressContents 1000454F4600 00030000 00xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 2010100948-- --00100C 28100630 202448-- 2020--3C2012 001000.

12 11 After Line 45  SYMTAB: LENGTH100C RDREC* THREE1003 ZERO1006 WRREC* EOF1000 ENDFIL2024 RETADR1009 BUFFER100F CLOOP2012 FIRST200F... SymbolValue 2013  201F 

13 12 110. 115. SUB TO READ RECORD INTO BUFFER 120. 1212039INPUTBYTEX’F1’F1 122203AMAXLENWORD4096001000 124. 125203DRDRECLDXZERO041006 1302040LDAZERO001009 1352043RLOOPTDINPUTE02039 1402046JEQRLOOP302043 1452049RDINPUT D82039 150204CCOMPZERO281006 155204FJEQEXIT30205B 1602052STCHBUFFER,X54900F 1652055TIXMAXLEN2C203A 1702058JLTRLOOP382043 175205BEXITSTXLENGTH10100C 180205ERSUB4C0000

14 13 Figure 2.19(b): After Line 160 Memory AddressContents 1000454F4600 00030000 00xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 201010094820 3D00100C 28100630 202448-- 2020--3C2012 0010000C 100F0010 030C100C 203048----08 10094C00 00F10010 00041006 2040001006E0 20393020 43DB2039 28100630 2050----5490 0F.

15 14 Figure 2.19(b): After Line 160 LENGTH100C RDREC203D THREE1003 ZERO1006 WRREC* EOF1000 ENDFIL2024 RETADR1009 BUFFER100F CLOOP2012 FIRST200F MAXLEN203A INPUT2039 EXIT* RLOOP2043... 201F 2031  2050 

16 15 195. 200. SUB TO WRITE RECORD FROM BUFFER 205. 2062061OUTPUTBYTEX’05’05 207. 2102062WRRECLDXZERO041006 2152065WLOOPTDOUTPUTE02061 2202068JEQWLOOP302065 225206BLDCHBUFFER,X50900F 230206EWDOUTPUTDC2061 2352071TIXLENGTH2C100C 2402074JLTWLOOP382065 2452077RSUB4C0000 255ENDFIRST

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

18 17 Fig. 2.20 (Partial) H COPY 001000 00107A T 001000 09 454F46 000003 000000 T 00200F 15 141009 480000 00100C 281006 300000 480000 3C2012 T 00201C 02 2024 T 002024 19 001000 0C100F 001003 0C100C 480000 081009 4C0000 T 002013 02 203D … E 00200F

19 18 Figure 2.20

20 19 Today ’ s Topic  Beck ’ s Section 2.4: Assembler Design Options One-pass assemblers Multi-pass assemblers

21 20 Multi-Pass Assemblers  Restriction on EQU and ORG No forward reference, since symbols’ value can’t be defined during the first pass  Example: ALPHAEQU BETA BETAEQU DELTA DELTARESW 1 Assemblers with 2 passes cannot resolve

22 21 Multi-Pass Assemblers  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

23 22 Figure 2.21(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&1MAXLEN/2  MAXLEN* HALFSZ  1 symbol undefined

24 23 Figure 2.21(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&1MAXLEN/2  MAXLEN&2 BUFEND- BUFFER BUFFER* MAXLEN   HALFSZ 

25 24 Figure 2.21(d): PREVBT 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&1MAXLEN/2  PREVBT&1BUFFER-1  MAXLEN&2 BUFEND- BUFFER BUFFER* MAXLEN  PREVBT  HALFSZ  MAXLEN

26 25 Figure 2.21(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&1MAXLEN/2  PREVBT1033  MAXLEN&1 BUFEND- BUFFER BUFFER1034  MAXLEN  Assume loc=1034 HALFSZ 

27 26 Figure 2.21(f): After Line 5 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER-1... 4 BUFFER RESB 4096 5 BUFEND EQU * BUFEND2034  HLFSZ800  PREVBT1033  MAXLEN1000  BUFFER1034 


Download ppt "CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University."

Similar presentations


Ads by Google