assembler

By sorrydear

345 0 0

More

assembler

345 0 0
By sorrydear

Put your story text here...

Page 1

1

Chapter 2 Assemblers

-- Basic Assembler Functions

Page 2

2

Outline

∎ Basic assembler functions

∎ A simple SIC assembler

∎ Assembler algorithm and data structure

Page 3

3

Basic assembler functions

∎ Translating mnemonic operation codes to

their machine language equivalents

∎ Assigning machine addresses to symbolic

labels

Source Program

• Mnemonic opcode

• Symbol

Assembler

Object code

Page 4

4

Assembler directive

∎ Assembler directives are pseudo instructions

They provide instructions to the assembler itself

They are not translated into machine operation codes

∎ SIC assembler directive

START : specify name & starting address

END

: end of source program, specify the first

execution instruction

BYTE, WORD, RESB, RESW

End of record

: a null char (00)

End of file

: a zero-length record

Page 5

5

Example program (Figure 2.1 pp. 45)

Forward

reference

Page 6

6

Example program (Figure 2.1 pp. 45)

Page 7

7

Example program (Figure 2.1 pp. 45)

Page 8

8

Example program (Figure 2.1 pp. 45)

∎ Purpose of example program

Reads records from input device (code F1)

Copies them to output device (code 05)

At the end of the file, writes EOF on the output device, then RSUB

to the operating system

∎ Data transfer (RD, WD)

A buffer is used to store record

Buffering is necessary for different I/O rates

The end of each record is marked with a null character (00)16

The end of the file is indicated by a zero-length record

∎ Subroutines (JSUB, RSUB)

RDREC, WRREC

Save link register first before nested jump

Page 9

9

A simple SIC assembler

∎ Assembler's functions

∎ Convert mnemonic operation codes to their machine

language equivalents

❖ Convert symbolic operands to their equivalent machine

addresses

∎ Decide the proper instruction format

∎ Convert the data constants to internal machine

representations

∎ Write the object program and the assembly listing

Page 10

10

Difficult

∎ Convert symbolic operands to their equivalent

machine addresses

∎ Forward reference

∎ 2 passes

∎ First pass: scan the source program for

label definitions and assign addresses

∎ Second pass: perform actual translation

Page 11

11

Example program with object code

(Figure 2.2 pp. 47)

Page 12

12

Example program with object code

(Figure 2.2 pp. 47)

Page 13

13

Example program with object code

(Figure 2.2 pp. 47)

Page 14

14

Format of object program

(Figure 2.3 pp.49)

Header record

Col. 1

H

Col. 2~7

Program name

Col. 8~13

Starting address of object program (hex)

Col. 14-19 Length of object program in bytes (hex)

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~69 Object code, represented in hex (2 col. per byte)

End record

Col.1

E

Col.2~7

Address of first executable instruction in object program (hex)

∎ "^" is only for separation only

Page 15

15

Format of object program

(Figure 2.3 pp.49)

Address 1033 ~ 2038: reserve storage by loader

• RETADR: 3 bytes

• LENGTH: 3 bytes

• BUFFER: 4096 bytes = (1000)16

Page 16

16

The two passes of an assembler

∎ Pass 1 (define symbols)

Assign addresses to all statements in the program

Save the addresses assigned to all labels for use in Pass 2

Perform assembler directives, including those for address

assignment, such as BYTE and RESW

∎ Pass 2 (assemble instructions and generate object

program)

Assemble instructions (generate opcode and look up addresses)

Generate data values defined by BYTE, WORD

Perform processing of assembler directives not done during Pass 1

Write the object program and the assembly listing

Page 17

17

Assembler algorithm

and data structures

∎ OPTAB: operation code table

∎ SYMTAB: symbol table

∎ LOCCTR: location counter

Source

Program

Object

Code

Pass 1

Intermediate

File

Pass 2

OPTAB

SYMTAB

LOCCTR

Assembler

The intermediate file include each source statement, assigned address and error indicator

Page 18

18

OPTABLE

∎ Mnemonic operation codes ⇔ Machine code

∎ Contain instruction format and length

∎ LOCCTR ← LOCCTR + (instruction length)

∎ Implementation

∎ It is a static table

∎ Array or hash table

∎ Usually use a hash table (mnemonic opcode

as key)

Page 19

19

LOCCTR

∎ Initialize to be the beginning address

specified in the "START" statement

∎ LOCCTR ← LOCCTR + (instruction length)

∎ The current value of LOCCTR gives the

address to the label encountered

Page 20

20

SYMTAB

∎ Label name ⇔ label address, type, length, flag

∎ To indicate error conditions (Ex: multiple define)

∎ It is a dynamic table

∎ Insert, delete and search

∎ Usually use a hash table

∎ The hash function should perform non-random

key (Ex: LOOP1, LOOP2, X, Y, Z)

Page 21

21

Algorithm Pass 1

(Figure 2.4(a), pp.53)

Page 22

22

Algorithm Pass 2

(Figure 2.4(b), pp.54)

Continue Reading

You'll Also Like

17K 135 15
Want to ask me questions? See my behind the scenes? Even see my upcoming story sneak peeks? There's even something better-talking to me about anythi...
Wattpad App - Unlock exclusive features