0% found this document useful (0 votes)
6 views

unit-1

Uploaded by

anchitaa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

unit-1

Uploaded by

anchitaa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Basic assembler functions

 Translating mnemonic operation codes to


their machine language equivalents
 Assigning machine addresses to symbolic
labels

Source Program
• Mnemonic opcode Assembler Object code
• Symbol

1
Forward
reference

2
3
4
5
6
7
 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


8
Address 1033 ~ 2038: reserve storage by loader
• RETADR: 3 bytes
• LENGTH: 3 bytes
• BUFFER: 4096 bytes = (1000)16

9
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

10
Assembler algorithm
and data structures
 OPTAB: operation code table
 SYMTAB: symbol table
 LOCCTR: location counter
Assembler

LOCCTR OPTAB SYMTAB

Source Object
Program Pass 1 Intermediate Pass 2 Code
File

The intermediate file include each source statement, assigned address and error indicato
11
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)

12
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

13
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)

14
Algorithm Pass 1

15
16
17

You might also like