2007-1-30cps4200 system programming 2007 spring 1 systems programming chapter 2 assembler i

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

Upload: stanley-hines

Post on 18-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

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

2007-1-30 CPS4200 System Programming 2007 Spring

1

Systems Programming

Chapter 2 Assembler

I

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

2007-1-30 CPS4200 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.

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

2007-1-30 CPS4200 System Programming 2007 Spring

3

2.1 Basic Assembler Function

• In addition to mnemonic machine instructions, we have the following assembler directive:START Specify name and starting address for the programEND Indicate the end of the source program and (optionally) specify the first executable instruction in the programBYTE Generate character or hexadecimal constant,

occupying as many bytes as needed to represent the constant

WORD Generate one-word integer constantRESB Reserve the indicated number of bytes for a data areaRESW Reserve the indicated number of words of a data area

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

2007-1-30 CPS4200 System Programming 2007 Spring

4

2.1 Basic Assembler Function

• See Figure 2-1.

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

2007-1-30 CPS4200 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

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

2007-1-30 CPS4200 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

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

2007-1-30 CPS4200 System Programming 2007 Spring

7

2.1.1 A Simple SIC Assembler

• Translation f unction #2 presents a problem:10 1000 First STL RETADR 141033

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 definition

s and assign addresses such as those in Loc column in Figure 2.2.

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

2007-1-30 CPS4200 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.

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

2007-1-30 CPS4200 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.

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

2007-1-30 CPS4200 System Programming 2007 Spring

10

2.1.1 A Simple SIC Assembler

Header record:

Col.1 H

Col. 2-7 Program name

Col. 8-13 Starting address of object program (Hex)

col. 14-19Length of object (Hex)program in bytes

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

2007-1-30 CPS4200 System Programming 2007 Spring

11

2.1.1 A Simple SIC Assembler

Text record:

col.1 T

col. 2-7 Starting address for object code in this record (Hex)

col. 8-9 Length of object code in this record in bytes (Hex)

col. 10-69Object code, represented in hexadecimal

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

2007-1-30 CPS4200 System Programming 2007 Spring

12

2.1.1 A Simple SIC Assembler

End record:

col.1 E

col. 2-7 address of first executable instruction in object program

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

2007-1-30 CPS4200 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.)

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

2007-1-30 CPS4200 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.