1 / 27

Assembler Design Options

Assembler Design Options. Department of Computer Science National Tsing Hua University. Today ’ s Topic. Beck ’ s Section 2.4: Assembler Design Options One-pass assemblers Multi-pass assemblers. One-Pass Assemblers (1/2). Main problem Forward references Data items

kimberly
Download Presentation

Assembler Design Options

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. Assembler Design Options Department of Computer Science National Tsing Hua University

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

  3. 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. 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. 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. 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. 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. Program for One-pass Assembler Line Loc Source statement Object code 0 1000 COPY START 1000 1 1000 EOF BYTE C’EOF’ 454F46 2 1003 THREE WORD 3 000003 3 1006 ZERO WORD 0 000000 4 1009 RETADR RESW 1 5 100C LENGTH RESW 1 6 100F BUFFER RESB 4096 10 200F FIRST STL RETADR 141009 15 2012 CLOOP JSUB RDREC 48203D 20 2015 LDA LENGTH 00100C 25 2018 COMP ZERO 281006 30 201B JEQ ENDFIL 302024 35 201E JSUB WRREC 482062 40 2021 J CLOOP 3C2012 45 2024 ENDFIL LDA EOF 001000 50 2027 STA BUFFER 0C100F 55 202A LDA THREE 001003 60 202D STA LENGTH 0C100C 65 2030 JSUB WRREC 482062 70 2033 LDL RETADR 081009 75 2036 RSUB 4C0000 Figure 2.18

  9. Memory Address Contents 1000 454F4600 00030000 00xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 2010 100948-- --00100C 28100630 ----48-- 2020 --3C2012 . . Address unknown yet Figure 2.19(a): Before Line 40

  10. Symbol Value 2013 201F 201C    Figure 2.19(a): Before Line 40 • SYMTAB:

  11. After Line 45 Memory Address Contents 1000 454F4600 00030000 00xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 2010 100948-- --00100C 28100630 202448-- 2020 --3C2012 001000 . .

  12. 2013 201F   After Line 45 Symbol Value • SYMTAB:

  13. 110 . 115 . SUB TO READ RECORD INTO BUFFER 120 . 121 2039 INPUT BYTE X’F1’ F1 122 203A MAXLEN WORD 4096 001000 124 . 125 203D RDREC LDX ZERO 041006 130 2040 LDA ZERO 001009 135 2043 RLOOP TD INPUT E02039 140 2046 JEQ RLOOP 302043 145 2049 RD INPUT D82039 150 204C COMP ZERO 281006 155 204F JEQ EXIT 30205B 160 2052 STCH BUFFER,X 54900F 165 2055 TIX MAXLEN 2C203A 170 2058 JLT RLOOP 382043 175 205B EXIT STX LENGTH 10100C 180 205E RSUB 4C0000

  14. Figure 2.19(b): After Line 160 Memory Address Contents 1000 454F4600 00030000 00xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx . 2000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx14 2010 10094820 3D00100C 28100630 202448-- 2020 --3C2012 0010000C 100F0010 030C100C 2030 48----08 10094C00 00F10010 00041006 2040 001006E0 20393020 43DB2039 28100630 2050 ----5490 0F .

  15. 201F 2050  Figure 2.19(b): After Line 160 2031 

  16. 195 . 200 . SUB TO WRITE RECORD FROM BUFFER 205 . 206 2061 OUTPUT BYTE X’05’ 05 207 . 210 2062 WRREC LDX ZERO 041006 215 2065 WLOOP TD OUTPUT E02061 220 2068 JEQ WLOOP 302065 225 206B LDCH BUFFER,X 50900F 230 206E WD OUTPUT DC2061 235 2071 TIX LENGTH 2C100C 240 2074 JLT WLOOP 382065 245 2077 RSUB 4C0000 255 END FIRST

  17. 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. 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. Figure 2.20

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

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

  22. 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. HALFSZ  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 * 1 symbol undefined

  24. MAXLEN MAXLEN HALFSZ    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 *

  25. MAXLEN HALFSZ MAXLEN   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 * PREVBT 

  26. MAXLEN HALFSZ   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 * Assume loc=1034

  27. 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 *

More Related