Module 2
Module 2
Assembler
• Fundamental functions
• Translating mnemonic operation codes to their machine language equivalents
• Assigning machine addresses to symbolic labels
• Machine dependency
• Different machine instruction formats and codes
Assembler Functions
• Convert mnemonic operation codes to their machine language
equivalents
• eg: translate STL to 14
• Convert symbolic operands to their equivalent machine addresses
• eg: translate RETADDR to 1033
• Build the machine instructions in the proper format
• Convert the data constants to internal machine representations
• eg: translate EOF to 454F46
• Write the object program and the assembly listing
Assembly language Program (Data Movement)
Label Instruction Operand
TEST START 1003
FIRST LDA FIVE
LDA 00
STA ALPHA
STA 0C
FIVE WORD 5
ALPHA RESW 1
END FIRST
Assembly language Program (Data Movement)
Loc Label Instruction Operand Object Code
1003 TEST START 1003
1003 FIRST LDA FIVE 00100C
1006 STA ALPHA 0C1009
1009 FIVE WORD 5 000005
100C ALPHA RESW 1 ******
100F END FIRST
Assembler
• Forward reference: reference to a label that is defined later in the
program.
• Most assemblers make two passes over the source program
• First pass: Scans the source program for label definitions
• Second pass: Performs most of the actual translation
Object Program
• 3 types of records
• Header record, Text record, End record
• Header Record
• Program name, starting address and length of the program
• Text Record
• Translated (machine code) instructions and data of the program together with
an indication of the address where they are to be loaded
• End Record
• Marks the end of the program and specifies the address in the program
where the execution is to begin
• Taken from the operand of the program’s END statement
• If no operand is specified, address of the first executable instruction is used
Object Program
• Header Record
Col. 1 H
Col. 2-7 Program name
Col. 8-13 Starting address of the object program (hexadecimal)
Col. 14-19 Length of object program in bytes (hexadecimal)
• Text Record
Col. 1 T
Col. 2-7 Starting address for object code in this record (hexadecimal)
Col. 8-9 Length of object code in this record in bytes (hexadecimal)
Col. 10-69 Object code, represented in hexadecimal (2 columns per byte of object code)
• End Record
Col. 1 E
Col. 2-7 Address of first executable instruction in the program (hexadecimal)
Object Program
• H^TEST ^001003^00000C
• T^001003^09^001009^0C100C^000005
• E^001003
Loc Label Instruction Operand Object
Code
1003 TEST START 1003
1003 FIRST LDA FIVE 001009
1006 STA ALPHA 0C100C
1009 FIVE WORD 5 000005
100C ALPHA RESW 1 ******
END FIRST
EXAMPLE
Text record:
Col. 1 T
Col. 2-7 Starting address for object code in this record (hexadecimal)
Col. 8-9 Length of object code in this record in bytes (hexadecimal)
Col. 10 – 69 Object code, represented in hexadecimal
End record:
Col. 1 E
Col. 2-7 Address of first executable instruction in object program
(hexadecimal)
Questions
1. Consider the statements in SIC program. Consider the program being assembled using a 2 pass
assembler.
Line no Location Label Opcode Operand
10 1000 LENGTH RESW 4
20 ------------ NEW WORD 3
What will be the address value assigned to the symbol NEW during pass 1? (5)
2. Write a sequence of instructions for SIC/ XE to find the average of three numbers, BETA, GAMMA and
DELTA. (3)
3. Explain the format of the object program generated by a two-pass SIC Assembler, highlighting the
contents of each record type. (3)
4. Explain the data structures used during the assembling process? Specify the uses of each during pass 1
and pass2 of a two pass assembler. (3)
6. Let A,B & C are arrays of 10 words each. Write a SIC/XE program to add the corresponding elements of A
& B and store the result in C (6)
7. What is meant by forward reference? How it is resolved by two pass assembler? (3)
Questions
8. Write the sequence of instructions in SIC, to transfer the string ”UNIVERSITY” stored at location LOCA1 to
LOCA2. (4)
9. Write a sequence of instructions for SIC/XE to set ALPHA equal to 4*BETA-9. Use immediate addressing
modes for constants and assume ALPHA and BETA to be floating point numbers (4)
10. Generate the assembled object program for the below SIC program. The machine code for the
instructions used are: LDX – 04, LDA – 00, ADD – 18, TIX – 2C, STA – 0C, JLT – 38 and RSUB – 4C. Show the
location counter value for each instruction (6)