130 likes | 191 Views
COP 3402. Lab 8. A Simple SIC Assembler. Functions to translate source program to object code: Convert mnemonic operation codes to machine language equivalents. Example: STL to 14 Convert symbolic operands to their equivalent machine addresses. Example: RETADR to 1033
E N D
COP 3402 Lab 8
A Simple SIC Assembler • Functions to translate source program to object code: • Convert mnemonic operation codes to machine language equivalents. Example: STL to 14 • Convert symbolic operands to their equivalent machine addresses. Example: RETADR to 1033 • Build the machine instructions in the proper format • Convert the data constants specified in the source program into their internal machine representations. Example: EOF to 454F46 • Write the object program and the assembly listing.
A Simple SIC Assembler cont. • Each of the functions except the second function can be taken care of by sequential processing of the program one line at a time. • Translating addresses can present a problem.
A Simple SIC Assembler cont. • Example: • 1000 FIRST STL RETADR 141033 Problem:forward reference, label is defined later in the program. Solution: Allow assembler to perform two passes over the source program. • First pass scans the source program for label definitions and assign address • Second pass performs actual translation
A Simple SIC Assembler cont. • Assembler processes assembler directives, which are instructions for the assembler itself. Example: START, specifies the starting memory address for the object program
Object Program Format • Contains: • Header: program name, starting address, length • Text: translated instructions, data of the program, and address where these are to be loaded • End: marks the end of the program and specifies the address in the program where execution begins
Object Program Format • Header Record: Col. 1: H Col. 2-7: Program name Col. 8-13: Starting address of the object program in hexadecimal Col. 14-19: Length of the object program in bytes
Object Program Format • Text Record: Col. 1: T Col. 2-7: Starting address for object code in this record Col. 8-9: Length of object code in this record in bytes Col. 10-69: Object code in hexadecimal
Object Program Format • End Record: Col. 1: E Col. 2-7: Address of first executable instruction in object program
Pass 1: Define symbols • 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.
Pass 2: assemble instructions and generate object program • Assemble instructions (translate operation codes and lookup addresses) • Generate data valoues defined by BYTE, WORD, etc • Perform processing of assembler directives not done during Pass 1. • Write the object program and assembly listing
Algorithm and Data Structures • Operation Code Table (OPTAB): used to look up mnemonic operation codes and translate them to their machine language equivalent • Symbol Table (SYMTAB): store values (addresses) assigned to labels. • Location counter (LOCCTR): helps in assignment of addresses. Initialized with addressed specified in START statement.
Algorithm and Data Structures cont. • During pass 1, OPTAB is used to look up and validate operation codes in the source program. • During pass 2, OPTAB is used to translate the operation codes to machine language. • During pass 1, labels are entered into SYMTAB as they are encountered together with their assigned addresses. • During pass 2, symbols used as operands are looked up SYMTAB to obtain addresses to be inserted in the assembled instructions.