Assignment No: 3 Title:: Problem Statement
Assignment No: 3 Title:: Problem Statement
ASSIGNMENT NO: 3
Problem Statement: -
Write a program in C/C++ for a two-pass assembler for hypothetical machine with
hypothetical set of instructions.
Objective: -
To study basic translation process of assembly language to machine language.
To study two pass assembly process.
Theory: -
A language translator bridges an execution gap to machine language of computer
system. An assembler is a language translator whose source language is assembly
language.
Language processing activity consists of two phases, Analysis phase and synthesis
phase. Analysis of source program consists of three components, Lexical rules, syntax
rules and semantic rules. Lexical rules govern the formation of valid statements in source
language. Semantic rules associate the formation meaning with valid statements of
language. Synthesis phase is concerned with construction of target language statements,
which have the same meaning as source language statements. This consists of memory
allocation and code generation.
Data structures
Pass I Pass II
Intermediate code
Data access
Control transfer
Synthesis Phase:
Obtain the machine operation code corresponding to the mnemonic operation code by
searching the mnemonic table.
Obtain the address of the operand from the symbol table.
Synthesize the machine instruction or the machine form of the constant as the case may
be.
Pass I: -
Separate the symbol, mnemonic opcode and operand fields.
Determine the storage-required foe every assembly language statement and update the
location counter.
Build the symbol table and the literal table.
Construct the intermediate code for every assembly language statement.
Pass II: -
Synthesize the target code by processing the intermediate code generated during
Hash table Implementation of MOT to minimize the search time required for searching
the instruction.
0 ADD IS 01 01 -1
1 BC IS 07 01 -1
2 COMP IS 06 01 -1
3 DIV IS 08 01 5
4 EQU AD 03 - 7
5 DC DL 01 - 6
6 DS DL 02 - -1
7 END AD 05 - -1
Hash Function used is ASCII Value of the First letter of Mnemonic – 65. This helps in
retrieving the op- code and other related information in minimum time. For Example the
instruction starting with alphabet ‘A’ will be found at index location 0, ‘B’ at index 1, so on
and so forth. If more instructions exist with same alphabet then the instruction is stored at
empty location and the index of that instruction is stored in the link field. Thus instructions
starting with alphabet ‘D’ will be stored at index locations 3,5,and 6. Those starting with E
will be stored at 4 and 7 and the process continues.
Symbol Address
Loop 204
Next 214 4. LITTAB: and POOLTAB : Literal table stores
the literals used in the program and
POOLTAB stores the pointers to the literals in the current literal pool.
Literal Address
= ‘5’
= ‘1’
= ‘1’
Start
Initialize Data
Structures
D
Read Next
Statement
Yes
Label
Present
Enter(Label, LC)
No into Symbol Table
Type of
Instruction
IS AD
B DL C
LC LC + Length
A B C
Yes END
No
Pass
II
Update LC
Generate
Intermediate
Code
SYMBOL TABLE
START 202
MOVER AREG, =’5 202) 04 1 210
MOVEM AREG , A 203) 05 1 220
LOOP MOVER AREG, A 204) 04 1 220
MOVER CREG, B 205) 04 3 221
ADD CREG, = ‘1’ 206) 01 3 211
MOVEM CREG, B 207) 05 3 221
SUB CREG, A 208) 03 3 220
BC ANY, NEXT 209) 07 6 214
LTORG 210) 00 0 005
211) 00 0 001
ADD CREG, B ’ 212) 01 3 221
BC LE LOOP 213) 07 2 204
NEXT SUB AREG, = ‘1’ 214) 02 1 222
BC LT, BACK 215) 07 1 220
STOP 216) 00 0 000
ORIGIN 219 217)
MULT CREG, B 219) 03 3 221
A DS 1 220)
BACK EQU LOOP 221)
B DS 1 221)
END 222) 00 0 001
Students are supposed to create two output files, one without errors & one with errors
indicating the type of error.
At least following errors must be handled.
Errors: -