MODULE -2 QUESTION BANK
1. Explain Assembler directives with example.
Assembler directives are pseudo instructions. They provide instructions to the assembler itself. They
are not translated into machine code.
START – Specify name and starting address for the program.
END – Indicate the end o the source program and(optionally) specify the first executable instruction in
the program.
BYTE – Generate character or hexadecimal constant , occupying as many bytes as needed to represent
the constant.
WORD- Generate one word integer constant.
RESB- Reserve the indicated number of bytes for a data area.
RESW- Reserve the indicated number of words for a data area.
2. What are the basic functions of an assembler
1. Convert mnemonic operation codes to their machine language equivalents. Eg: translate STL to 14.
2. Convert symbolic operands to their equivalent machine addresses. Eg: translate RETADR to 1033
3. Build the machine instructions in the proper format
4. Convert the data constants specified in the source program into their internal machine
representations.- eg: translate EOF to 454F46
5. Write the object program and assembly listing.
3. Write the object program format
4. Explain the datastructures used in assembler algorithm
The simple assembler uses two major internal data structures: the operation Code Table (OPTAB)
and the Symbol Table (SYMTAB).
OPTAB:
• It is used to lookup mnemonic operation codes and translates them to their machine language
equivalents. In more complex assemblers the table also contains information about instruction
format and length.
• In pass 1 the OPTAB is used to look up and validate the operation code in the source program.
In pass 2, it is used to translate the operation codes to machine language. In simple SIC machine
this process can be performed in either in pass 1 or in pass 2. But for machine like SIC/XE that
has instructions of different lengths, we must search OPTAB in the first pass to find the
instruction length for incrementing LOCCTR.
• In pass 2 we take the information from OPTAB to tell us which instruction format to use in
assembling the instruction, and any peculiarities of the object code instruction.
• OPTAB is usually organized as a hash table, with mnemonic operation code as the key. The
hash table organization is particularly appropriate, since it provides fast retrieval with a
minimum of searching. Most of the cases the OPTAB is a static table- that is, entries are not
normally added to or deleted from it. In such cases it is possible to design a special hashing
function or other data structure to give optimum performance for the particular set of keys being
stored.
SYMTAB:
• This table includes the name and value for each label in the source program, together with
flags to indicate the error conditions (e.g., if a symbol is defined in two different places).
• During Pass 1: labels are entered into the symbol table along with their assigned address value
as they are encountered. All the symbols address value should get resolved at the pass 1.
• During Pass 2: Symbols used as operands are looked up the symbol table to obtain the address
value to be inserted in the assembled instructions.
• SYMTAB is usually organized as a hash table for efficiency of insertion and retrieval.
Since entries are rarely deleted, efficiency of deletion is the important criteria for optimization.
• Both pass 1 and pass 2 require reading the source program. Apart from this an intermediate file
is created by pass 1 that contains each source statement together with its assigned address, error
indicators, etc. This file is one of the inputs to the pass 2.
LOCCTR:
• Apart from the SYMTAB and OPTAB, this is another important variable which helps in the
assignment of the addresses. LOCCTR is initialized to the beginning address mentioned in the
START statement of the program. After each statement is processed, the length of the assembled
instruction is added to the LOCCTR to make it point to the next instruction. Whenever a label
is encountered in an instruction the LOCCTR value gives the address to be associated with that
label.
5. Write the pass1 algorithm of an assembler
6. Write the pass2 algorithm of an assembler
7. Give the format of the following. a. Header record b. Text record c. End record
Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address (hex)
Col. 14-19 Length of object program in bytes (hex)
Text
Col.1 T
Col.2~7 Starting address in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code (69-10+1)/6=10 instructions
End
Col.1 E
Col.2~7 Address of first executable instruction (hex)
(END program_name
8. Assume that ALPHA is an array of 100 words. Write a sequence of instructions for SIC/XE to
find the maximum element in the array and store results in MAX.
LDS #3
LDT #300
LDX #0
CLOOP LDA ALPHA, X
COMP MAX
JLT NOCH
STA MAX
NOCH ADDR S, X
COMPR X, T
JLT CLOOP
ALPHA RESW 100
MAX WORD -32768
9. Write a sequence of instructions for SIC/XE to divide BETA by GAMMA, setting ALPHA to
the integer portion of the quotient and DELTA to the remainder. Use register-to-register
instructions to make the calculation as efficient as possible.
Assembly Code:
LDA BETA
LDS GAMMA
DIVR S, A
STA ALPHA
MULR S, A
LDS BETA
SUBR A, S
STS DELTA
:
:
ALPHA RESW 1
BETA RESW 1
GAMMA RESW 1
DELTA RESW 1
10. Write a sequence of instructions for SIC/XE to set ALPHA equal to 4 * BETA – 9. Assume
that ALPHA and BETA are defined as in Fig. 1.3(b). Use immediate addressing for the
constants.
Assembly Code:
LDA BETA
LDS #4
MULR S,A
SUB #9
STA ALPHA
:
:
ALPHA RESW 1
7. Generate the complete object code for the ALP.Assume suitable machine equivalents from the
mnemonic opcodes. (10 Marks)
OPCODES:LDX-04 LDA-00 LDB-68 ADD-18 TIX-2C STA-0C JLT-38 RSUB-4C
• Calculation of Addresses – 2 Marks
• Generating Object Code – 8 Marks
SUM START 0000
0000 FIRST LDX #0 050000h
0003 LDA #0 010000h
0006 +LDB #TABLE2 69100320h
BASE TABLE2
000A LOOP ADD TABLE,X 1BA013
000D ADD TABLE2,X 1BA310
0010 TIX COUNT 2F200A
0013 JLT LOOP 3B2FF4
0016 +STA TOTAL 0F100920h
001A RSUB 4F0000
001D COUNT RESW 1
0020 TABLE RESW 0100H
0320 TABLE2 RESW 0200H
0920 TOTAL RESW 1
0923 END FIRST
1. LDX #0 ,LDX-04
000001 0 1 0 0 0 0 0000 0000 0000
Object Code : 050000h
2. LDA #0 ,LDA - 00
000000 0 1 0 0 0 0 0000 0000 0000
Object Code : 010000h
3. +LDB #TABLE2 ,LDB-68 –Format 4 instruction
0110 10 0 1 0 0 0 1 0000 0000 0011 0010 0000
Object Code : 69100320h
4. ADD TABLE , X , ADD-18 – Format 3 Instruction
0001 10 1 1 1 0 1 0 0000 0001 0011
Displacement = TA – PC
= 0020 – 000D = 013
Object Code : 1BA013
5. ADD TABLE2 , X , ADD-18 – Format 3 instruction
0001 10 1 1 1 0 1 0 0011 0001 0000
Displacement = TA-PC = 0320-0010 = 0310
Object Code : 1BA310
6. TIX COUNT ,TIX – 2C ,Format 3 Instruction
0010 11 1 1 0 0 1 0 0000 0000 1010
Displacement = TA-PC = 001D – 0013 = 00A
Object Code : 2F200A
7. JLT LOOP , JLT - 38
0011 10 1 1 0 0 1 0 1111 1111 0100
Displacement = TA-PC = 000A – 0016 = FF4
Object Code : 3B2FF4
8. +STA TOTAL ,STA -0C
0000 11 1 1 0 0 0 1 0000 0000 1001 0010 0000
Object Code : 0F100920
9. RSUB ,
RSUB –
4C
Object
Code :
4F0000
11.