Presentation is loading. Please wait.

Presentation is loading. Please wait.

2007-1-30CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.

Similar presentations


Presentation on theme: "2007-1-30CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I."— Presentation transcript:

1 2007-1-30CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I

2 2007-1-30CPS4200 System Programming 2007 Spring 2 2. Assembler Functions of assembler: –Translating mnemonic operation codes (assembly codes) to their machine language equivalent; and – Assigning machine addresses to symbolic labels used by the programmer.

3 2007-1-30CPS4200 System Programming 2007 Spring 3 2.1 Basic Assembler Function In addition to mnemonic machine instructions, we have the following assembler directive: STARTSpecify name and starting address for the program ENDIndicate the end of the source program and (optionally) specify the first executable instruction in the program BYTEGenerate character or hexadecimal constant, occupying as many bytes as needed to represent the constant WORDGenerate one-word integer constant RESBReserve the indicated number of bytes for a data area RESWReserve the indicated number of words of a data area

4 2007-1-30CPS4200 System Programming 2007 Spring 4 2.1 Basic Assembler Function See Figure 2-1.

5 2007-1-30CPS4200 System Programming 2007 Spring 5 2.1.1 A Simple SIC Assembler Figure 2-2 is the generated object code from Figure 2-1. –Loc: machine address –The program starts at address 1000

6 2007-1-30CPS4200 System Programming 2007 Spring 6 2.1.1 A Simple SIC Assembler Translation functions: 1.Convert mnemonic operation codes to their machine language equivalents. 2.Convert symbolic operands to their equivalent machine addresses 3.Build the machine instructions in the proper format 4.Convert the data constants specified in the source program into their internal machine representations 5.Write the object program and the assembly listing

7 2007-1-30CPS4200 System Programming 2007 Spring 7 2.1.1 A Simple SIC Assembler Translation f unction #2 presents a problem: 101000FirstSTL RETADR141033 RETADR’s address is not known yet when we process the translation!! forward reference – a reference to a label (RETADR) that is defined later in the program. Solution: Two passes compilation –First pass scan the source program for label definitions and assign addresses such as those in Loc column in Figure 2.2.

8 2007-1-30CPS4200 System Programming 2007 Spring 8 2.1.1 A Simple SIC Assembler In addition to translating the instructions of the source program, the assembler must process statements called assembler directive. –They provide instruction to the assembler itself. –Example, BYTE, WORD, RESB, RESW, START, END.

9 2007-1-30CPS4200 System Programming 2007 Spring 9 2.1.1 A Simple SIC Assembler Finally, the assembler must write the generated object code onto some output device. –Three types of records: Header, Text, and End. Header: contains the program name, starting address, and length. Text records: contains the translated instructions and data of the program, together with an indication of the addresses where these are to be loaded. End Record: marks the end of the object program and specifies the address in the program where execution is to begin.

10 2007-1-30CPS4200 System Programming 2007 Spring 10 2.1.1 A Simple SIC Assembler Header record: Col.1H Col. 2-7Program name Col. 8-13Starting address of object program (Hex) col. 14-19Length of object (Hex) program in bytes

11 2007-1-30CPS4200 System Programming 2007 Spring 11 2.1.1 A Simple SIC Assembler Text record: col.1T col. 2-7Starting address for object code in this record (Hex) col. 8-9Length of object code in this record in bytes (Hex) col. 10-69Object code, represented in hexadecimal

12 2007-1-30CPS4200 System Programming 2007 Spring 12 2.1.1 A Simple SIC Assembler End record: col.1E col. 2-7address of first executable instruction in object program

13 2007-1-30CPS4200 System Programming 2007 Spring 13 2.1.1 A Simple SIC Assembler Pass1 (define symbols) –Assign addresses to all statements in the program –Save the values (addresses) assigned to all labels for use in Pass 2. –Perform some processing of assembler directives. (This includes processing that effects address assignment, such as determining the length of data areas defined by BYTE, RESW, etc.)

14 2007-1-30CPS4200 System Programming 2007 Spring 14 2.1.1 A Simple SIC Assembler Pass2 (assemble instructions and generate object program) –Assemble instructions. (translating operation codes and looking up addresses.) –Generate data values defined by BYTE, WORD, etc. –Perform processing of assembler directive not done during Pass 1. –Write the object program and the assembly listing.


Download ppt "2007-1-30CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I."

Similar presentations


Ads by Google