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

Slides:



Advertisements
Similar presentations
Chapter 3 Loaders and Linkers
Advertisements

Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.
Machine Independent Assembler Features
Assembler Design Options
Machine-Independent Loader Features
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Assembler design.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Chih-Hung Wang Chapter 2: Assembler (Full) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
System Software by Leland L. Beck Chapter 2
Assembler – Assembler Design Options. One-Pass Assemblers (1/2) Main problem  Forward references Data items Labels on instructions Solution  Data items:
Loader- Machine Independent Loader Features
Chapter 2 Assemblers Assembler Linker Source Program Object Code
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Assembler – Machine Dependent Features
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming December 7, 2006.
CS2422 Assembly Language & System Programming November 30, 2006.
CS2422 Assembly Language & System Programming December 26, 2006.
Machine-Independent Assembler Features
Assembler (Basic Functions)
Assembler – Machine Independent Features. Literals Design idea  Let programmers to be able to write the value of a constant operand as a part of the.
CS2422 Assembly Language & System Programming December 14, 2006.
UNIT II ASSEMBLERS.
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
Chapter 4 System Programming and Operating Systems -DM Dhamdhere
Assembler Design Options
What is System Software? -a program that manages and supports the computer resources - manages operations of a computer system while it executes various.
Assemblers.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software by Leland L. Beck Chapter 2.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
Machine-Independent Assembler Features Literals, Symbol-Defining Statements, Expressions, Program Blocks, Control Sections and Program Linking.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Machine Independent Assembler Features
Assemblers System Software by Leland L. Beck Chapter 2.
Loader and Linker.
Assemblers Two functions: – Mnemonic opcode  Machine Code – Symbolic labels  machine addresses (in memory) Some features: – Depend on assembly language.
Assembler Design Options One-Pass and Multi-Pass Assemblers.
Assemblers System Software.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
ADHIPARASAKTHI ENGINEERING COLLEGE
CC410: System Programming
Machine dependent Assembler Features
CC410: System Programming
Machine Independent Assembler Features
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Machine Independent Assembler Features
Chapter 9 : Assembler Design Options
Assembler Design Options
Assembler Design Options
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Optional Assembler Features
Machine Independent Features
Assembler Design Options
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Machine Independent Assembler Features
Presentation transcript:

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

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

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

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

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

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

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

7 Program for One-pass Assembler LineLoc Source statementObject code 01000COPYSTART EOFBYTEC’EOF’454F THREEWORD ZEROWORD RETADRRESW1 5100CLENGTHRESW1 6100FBUFFERRESB FFIRSTSTLRETADR CLOOPJSUBRDREC48203D LDALENGTH00100C COMPZERO BJEQENDFIL EJSUBWRREC JCLOOP3C ENDFILLDAEOF STABUFFER0C100F 55202ALDATHREE DSTALENGTH0C100C JSUBWRREC LDLRETADR RSUB4C0000 Figure 2.18

8 Figure 2.19(a): Before Line 40 Memory AddressContents F xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx C C2012. Address unknown yet

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

10 After Line 45 Memory AddressContents F xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx C C

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

SUB TO READ RECORD INTO BUFFER INPUTBYTEX’F1’F AMAXLENWORD DRDRECLDXZERO LDAZERO RLOOPTDINPUTE JEQRLOOP RDINPUT D CCOMPZERO FJEQEXIT30205B STCHBUFFER,X54900F TIXMAXLEN2C203A JLTRLOOP BEXITSTXLENGTH10100C ERSUB4C0000

13 Figure 2.19(b): After Line 160 Memory AddressContents F xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx. 2000xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx D00100C C C 100F C100C C00 00F E DB F.

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

SUB TO WRITE RECORD FROM BUFFER OUTPUTBYTEX’05’ WRRECLDXZERO WLOOPTDOUTPUTE JEQWLOOP BLDCHBUFFER,X50900F EWDOUTPUTDC TIXLENGTH2C100C JLTWLOOP RSUB4C ENDFIRST

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

17 Fig (Partial) H COPY A T F T 00200F C C2012 T 00201C T C100F C100C C0000 T D … E 00200F

18 Figure 2.20

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

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

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

22 Figure 2.21(a): After Pass 1 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER BUFFER RESB BUFEND EQU * HALFSZ&1MAXLEN/2  MAXLEN* HALFSZ  1 symbol undefined

23 Figure 2.21(c): MAXLEN Defined 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER BUFFER RESB BUFEND EQU * BUFEND* HALFSZ&1MAXLEN/2  MAXLEN&2 BUFEND- BUFFER BUFFER* MAXLEN   HALFSZ 

24 Figure 2.21(d): PREVBT Defined 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER BUFFER RESB BUFEND EQU * BUFEND* HLFSZ&1MAXLEN/2  PREVBT&1BUFFER-1  MAXLEN&2 BUFEND- BUFFER BUFFER* MAXLEN  PREVBT  HALFSZ  MAXLEN

25 Figure 2.21(e): After Line 4 1 HALFSZ EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER BUFFER RESB BUFEND EQU * BUFEND* HLFSZ&1MAXLEN/2  PREVBT1033  MAXLEN&1 BUFEND- BUFFER BUFFER1034  MAXLEN  Assume loc=1034 HALFSZ 

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