2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.

Slides:



Advertisements
Similar presentations
Chapter 3 Loaders and Linkers
Advertisements

3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Machine Independent Assembler Features
Assembler Design Options
System Software Chih-Shun Hsu
Machine-Dependent Assembler Features (SIC/XE Assembler) Instruction Formats, Addressing Modes, and Program Relocation.
Chapter 6: Machine dependent Assembler Features
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
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:
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.
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
An introduction to systems programming
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.
A Simple Two-Pass Assembler
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.
Chapter 1 Computer architecture Languages: machine, assembly, high
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
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.
CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.
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.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Machine Independent Assembler Features
G.Umamaheswari Lect/IT R.M.D.EC system software
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.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
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 Programming and administration
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
Assembler Design Options
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Machine Independent Assembler Features
An introduction to systems programming
Presentation transcript:

2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate mnemonic operation codes to machine language equivalents. Overview: r Basic Assembler Functions r Machine-Dependent Assembler Features r Machine-Independent Assembler Features r Assembler Design Options

2 : Assembler 2 r Assembler directives: m START : Specify name and starting address for the program m END : … m BYTE : Generate character or hexdecimal constant m WORD: Generate one-word integer constant m RESB : Reserve the indicated number of bytes for a data area m RESW : … Basic Assembler Functions (Using SIC as an Example)

2 : Assembler 3 Example of a SIC Assembler Language Program

2 : Assembler 4 Example of a SIC Assembler Language Program (cont.)

2 : Assembler 5 Example of a SIC Assembler Language Program (cont.)

2 : Assembler 6 A Simple SIC Assembler r The translation steps m Convert mnemonic operation codes to their machine language equivalent. m Convert symbolic operands to their equivalent machine addresses. m Build the machine instructions in the proper format. m Convert the data constants specified in the source program into their internal machine representations. m Write the object program and the assembly listing.

2 : Assembler 7 Output: the object program

2 : Assembler 8 The Object code for the above program

2 : Assembler 9 The Object code for the above program (cont.)

2 : Assembler 10 The Object code for the above program (cont.)

2 : Assembler 11 The Format for Object Program r The object program will later be loaded into memory for execution. r Three types of records for object program format m Header: contains the program name, starting address, and length. m Text: contains the translated instructions and data of the program m End: marks the end of the object program and specifies the address in the program where execution is to begin.

2 : Assembler 12 The Format for Object Program (cont.)

2 : Assembler 13 The object program

2 : Assembler 14 Two Passes of our Simple Assembler

2 : Assembler 15 The Data Structures r Two major data structures: r Operation code table (OPTAB) r Symbol table (SYMTAB) r Note: SYMTAB is usually organized as a hash table for efficiently of insertion and retrieval. r Location counter (LOCCTR)

2 : Assembler 16 The Algorithm (Pass 1)

2 : Assembler 17 The Algorithm (Pass 2)

2 : Assembler 18 Machine-Dependent Assembler Features (using SIC/XE as an example) r Addressing modes m Immediate addressing modes: COMP #0 m Indirect addressing: m The extended instruction format +LDT #4096 m Most of the register-to-memory instructions are assembled using either program-counter relative or base relative addressing. If either program-counter relative nor base relative addressing can be used, then the 4-byte (Format 4) must be used..

2 : Assembler 19 Example of a SIC/XE Assembler Language Program

2 : Assembler 20 Example of a SIC/XE Assembler Language Program (cont.)

2 : Assembler 21 Example of a SIC/XE Assembler Language Program (cont.)

2 : Assembler 22 Output: the object program

2 : Assembler 23 The Object code for the above program

2 : Assembler 24 The Object code for the above program (cont.)

2 : Assembler 25 The Object code for the above program (cont.)

2 : Assembler 26 Program Relocation r An object program that contains the information necessary to perform this kind of modification is called a relocatable program.

2 : Assembler 27 Program Relocation (cont.) r We can solve the relocation problem in the following way: r 1. When the assembler generates the object code for the JSUB instruction we are considering, it will insert the address of RDREC relative to the start of the program. (This is the reason we initialized the location counter to 0 for the assembly) r 2. The assembler will also produce a command for the loader, instructing it to add the beginning address of the program to the address field in the JSUB instruction at load time.

2 : Assembler 28 Program Relocation (cont.)

2 : Assembler 29 Program Relocation (cont.)

2 : Assembler 30 Machine-Independent Assembler Features r Literals r Symbol-Defining Statements r Expressions r Program Blocks r Control Sections and Program Linking

2 : Assembler 31 r It is often convenient for the programmer to be able to write the values of a constant operand as a part of the instruction that uses it. Such an operands is called a literal. r E.g., (In Fig 2.9) r A ENDFIL LDA =C’EOF’ r WLOOP TD =X’05’ E32011 r The difference between a literal and an immediate operand. With immediate addressing, the operand value is assembled as part of the machine instruction. With a literal, the assembler generate the specified value as a constant at some other memory location. Literal

2 : Assembler 32 r Literal pools: Normally literals are placed into a pool at the end of the program. The assembly listing of a program containing literals usually includes a listing of this literal pool, which shows the assigned addresses and the generated data values. r The assembler directive LTORG is used for creating the literal pool. Literal (cont.)

2 : Assembler 33 Program demonstrating additional assembler features

2 : Assembler 34 Program demonstrating additional assembler features (cont.)

2 : Assembler 35 Program demonstrating additional assembler features (cont.)

2 : Assembler 36 The above program with object code

2 : Assembler 37 The above program with object code (cont.)

2 : Assembler 38 The above program with object code (cont.)

2 : Assembler 39 Symbol-Defining Statements r Most assembler provides an assembler directive that allows the programmer to define symbols and specify their values. r The assembler directive : EQU r E.g., symbolEQUvalue r Usage sample: +LDT#4096 +LDT#MAXLEN MAXLENEQU4096

2 : Assembler 40 r STABRESB 1100 r SYMBOLEQUSTAB r VALUEEQUSTAB+6 r FLAGSEQUSTAB+9 r LDAVALUE,X Symbol-Defining Statements (An example…)

2 : Assembler 41 Expressions r Assembler generally allow arithmetic expressions formed according to the normal rules using the operators +, -, *, and / r E.g., MAXLENEQUBUFEND-BUFFER

2 : Assembler 42 Program Blocks r The source program logically contained subroutines, data areas, etc. However they were handled by the assembler as one entity, resulting in a single block of object code. r Note: The term program blocks refer to segments of code that are rearranged within a single object program unit, and control section to refer to segments that are translated into independent object program units. r The assembler directive USE indicates which portions of the source program belong to the various blocks.

2 : Assembler 43 Example of a program with multiple program blocks

2 : Assembler 44 Example of a program with multiple program blocks (cont.)

2 : Assembler 45 Example of a program with multiple program blocks (cont.)

2 : Assembler 46 The above program with object code

2 : Assembler 47 The above program with object code (cont.)

2 : Assembler 48 The above program with object code (cont.)

2 : Assembler 49 Program Blocks r Pass 1 Use separate location counter for each program block. r Pass 2 The assembler needs the address for each symbol relative to the start of the object program.

2 : Assembler 50 The object program

2 : Assembler 51 The loading processes

2 : Assembler 52 Control sections and program linking r A control section is a part of the program that maintain its identity after assembly; each such control section can be loaded and relocated independently of the others. r Note: 1. The assembler has no idea where any other control section will be loaded at execution time. 2. The reference between control sections are called external reference. r Two assembler directive: 1. EXTDEF: defined the external symbol that may be used by other sections. 2. EXTREF: named the symbols that are used in this control section and defined elsewhere.

2 : Assembler 53 Illustration of control sections and program linking

2 : Assembler 54 Illustration of control sections and program linking (cont.)

2 : Assembler 55 Illustration of control sections and program linking (cont.)

2 : Assembler 56 The above program with object code

2 : Assembler 57 The above program with object code (cont.)

2 : Assembler 58 The above program with object code (cont.)

2 : Assembler 59 Control sections and program linking (cont.) r The two new record types are Define and Refer.

2 : Assembler 60 The object program

2 : Assembler 61 Assembler Design Options – One-pass Assembler r Main problem: r One need to solve the forward reference problem. r Solution: r Require all such areas be defined in the source program before they are referenced. r In order to reduce the size of the problem, many one-pass assemblers prohibit forward reference to data items. r Usually one-pass assembler generate object code in memory for immediate execution. No object program is written out, and no loader is needed load-and-go assembler.

2 : Assembler 62 Assembler Design Options – One-pass Assembler (cont.) r If an instruction operand is a symbol that has not yet been defined, the operand address is omitted when the instruction is assembled. r The address of the operand field of the instruction that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry. r When the definition for a symbol is encountered, the forward reference list for that symbol is scanned, and the proper address is inserted into any instructions previously generated.

2 : Assembler 63 Sample program for a one-pass assembler

2 : Assembler 64 Sample program for a one-pass assembler (cont.)

2 : Assembler 65 Sample program for a one-pass assembler (cont.)

2 : Assembler 66 Object code in memory and symbol table entries for above program (after scanning line 40)

2 : Assembler 67 Object code in memory and symbol table entries for above program (after scanning line 160)

2 : Assembler 68 Object program from one-pass assembler for above program

2 : Assembler 69 Assembler Design Options – Multi-pass Assembler

2 : Assembler 70 Example of multi-pass assembler operation

2 : Assembler 71 Example of multi-pass assembler operation (cont.)

2 : Assembler 72 Example of multi-pass assembler operation (cont.)

2 : Assembler 73 Example of multi-pass assembler operation (cont.)

2 : Assembler 74 Example of multi-pass assembler operation (cont.)