0% found this document useful (0 votes)
2 views34 pages

Module 2

The document details the functions and structure of an assembler, including its role in translating mnemonic operation codes to machine language and managing symbolic labels. It describes the two-pass assembly process, the creation of object programs with header, text, and end records, and the internal data structures such as the Operation Code Table (OPTAB) and Symbol Table (SYMTAB). Additionally, it includes examples of assembly language programs and questions related to the concepts discussed.

Uploaded by

aswaatemp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views34 pages

Module 2

The document details the functions and structure of an assembler, including its role in translating mnemonic operation codes to machine language and managing symbolic labels. It describes the two-pass assembly process, the creation of object programs with header, text, and end records, and the internal data structures such as the Operation Code Table (OPTAB) and Symbol Table (SYMTAB). Additionally, it includes examples of assembly language programs and questions related to the concepts discussed.

Uploaded by

aswaatemp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assembler

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 ******
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

SUM START 4000


FIRST LDA ALPHA
ADD INCR
SUB ONE
STA BETA Mnemonic Machine
LDA GAMMA Operation Language
Code Equivalent
ADD INCR
ADD 18
SUB ONE
LDA 00
STA DELTA
SUB 1C
ONE WORD 1
STA 0C
ALPHA RESW 1
BETA RESW 1
GAMMA RESW 1
DELTA RESW 1
INCR RESW 1
END FIRST
EXAMPLE

4000 SUM START 4000 OPTAB


4000 FIRST LDA ALPHA 00401B Mnemonic Machine
4003 ADD INCR 184027 Operation Language
Code Equivalent
4006 SUB ONE 1C4018
ADD 18
4009 STA BETA 1C401E
LDA 00
400C LDA GAMMA 004021
SUB 1C
400F ADD INCR 184027
STA 0C
4012 SUB ONE 1C4018
4015 STA DELTA 0C4024 SYMTAB
4018 ONE WORD 1 000001 Symbol Address
401B ALPHA RESW 1 ONE 4018
401E BETA RESW 1 ALPHA 401B
4021 GAMMA RESW 1 BETA 401E
4024 DELTA RESW 1 GAMMA 4021
4027 INCR RESW 1 DELTA 4024
END FIRST INCR 4027
Data Structures
• Two major internal data structures:
• Operation Code Table (OPTAB)
• Symbol Table (SYMTAB)
• Variable: Location Counter(LOCCTR)
Data Structures
• Operation Code Table (OPTAB)
• Used to look up mnemonic operation codes and translate them into machine
language equivalents
• Contains the mnemonic operation code and its machine language equivalent
• In more complex assemblers, contains information like instruction format and
length
Mnemonic Machine Length
• Characteristic Operation Language (bytes)
• Static table Code Equivalent
ADD 18 3
• Entries are not normally added or deleted
LDA 00 3
Data Structures
• Pass 1
• Used to look up and validate opcodes in the source program
• Pass 2
• Used to translate the operation codes to machine language
• Implementation
• Organized as a hash table with mnemonic operation code as the key
• Provides retrieval with minimum of searching
• Information in OPTAB is predefined when the assembler itself is written
Data Structures
• Symbol Table (SYMTAB)
• Used to store values (addresses) assigned to labels
• Includes the name and value for each label
• Flags to indicate error conditions, e.g. duplicate definition of labels
• May contain other information about the data area or instruction labeled like
type or length
• Characteristic
LABEL Address (LOCCTR
• Dynamic table (insert, delete, search) value)
• Deletion is performed rarely FIRST 1003
• Implementation FIVE 1009
• Hash table ALPHA 100C
• For efficiency of insertion and retrieval
Data Structures
• Pass1
• Labels are entered into the symbol table along with their assigned addresses
(from LOCCTR)
• Pass2
• Address of the symbols used as operands are looked up in SYMTAB to insert
the address in the assembled instructions
Data Structures
• LOCCTR
• Used to help in the assignment of addresses
• Initialized to the beginning address specified in the START statement
• After each source statement is processed, the length of the assembled
instruction or data area to be generated is added
• Gives the address of a label
• Counted in bytes
Two Pass Assembler
• Pass 1
• Assign addresses to all statements in the program
• Save the values (addresses) assigned to all labels for use in Pass 2
• Perform some processing of assembler directives.
• This includes processing that affects the address assignments such as
determining the length of the data areas defined by BYTE, RESB, RESW etc.
• Pass 2
• Assemble instructions
• Generate data values defined by BYTE, WORD
• Perform processing of assembler directives not done in Pass 1
• Write the object program and the assembly listing
Pass 1 Algorithm
Pass 1 Algorithm
SIC Program
•a
SIC Program
SYMTAB OPTAB
FIRST 1000 STL 14
CLOOP 1003 JSUB 48
ENDFIL 1015 LDA 00
EOF 102A COMP 28
THREE 102D JEQ 30
ZERO 1030 J 3C
RETADR 1033 STA 0C
LENGTH 1036 LDL 08
BUFFER 1039 RSUB 4C
RDREC 2039 LDX 04
WRREC 2061
SIC Program- Pass 2 Output
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 and their purposes in a two-pass assembler. (3)
5. What is the difference between the instructions LDA #5 and LDA FIVE? Explain how each instruction is
executed. (3)
6. What are the uses of OPTAB and SYMTAB during the assembling process? Specify the uses of each during
pass 1 and pass2 of a two pass assembler. (3)
Questions
7. What is meant by forward reference? How it is resolved by two pass assembler? (3)
8. 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)
9. Write the sequence of instructions in SIC/XE to add two integer arrays S and T and store the contents to array
Z. S and T each contains 10 integers (4)
10. Write the sequence of instructions in SIC, to transfer the string ”UNIVERSITY” stored at location LOCA1 to
LOCA2. (4)
11. 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)
PGM START 1000
LDF #4
MULF BETA
SUBF #9
STF ALPHA
BETA BYTE 09 11 0A 23 24 56 ; 6 byte floating point number
ALPHA RESB 6
END 1000
Questions
12. 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)

You might also like