COP 3402 System Software Recitation Notes 2 nd

  • Slides: 13
Download presentation
COP 3402 System Software Recitation Notes 2 nd November 2007

COP 3402 System Software Recitation Notes 2 nd November 2007

Assemblers Recap • Assemblers – Task is to read in Assembly code – Output

Assemblers Recap • Assemblers – Task is to read in Assembly code – Output is object code.

Recap Contd • Forward Referencing can be a problem • Example • Line 10:

Recap Contd • Forward Referencing can be a problem • Example • Line 10: store the value of L register in RETADR. • But RETADR is’nt defined Yet. It is defined on line 95.

Recap Contd • We cannot translate the program from assembly code to object code

Recap Contd • We cannot translate the program from assembly code to object code in one pass [due to forward Referencing]. • Solution is to use two passes. – First pass scans the source code for labels and constructs the symbol table – Second pass generates the object code using the symbol table.

Object Program Format • Contains: – Header: program name, starting address, length – Text:

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

Pass 1: Define symbols 1. Assign addresses to all statements in the program 2.

Pass 1: Define symbols 1. Assign addresses to all statements in the program 2. Save the values (addresses) assigned to all labels for use in pass 2 3. Perform some processing of assembler directives. Examples are variable/constant declarations (RESW, WORD, . . )

Pass 2: assemble instructions and generate object program 1. 2. 3. 4. Assemble instructions

Pass 2: assemble instructions and generate object program 1. 2. 3. 4. Assemble instructions (translate operation codes and lookup addresses) Generate data values 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

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

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.

Pass 1 – Pseudo Code • First find starting address of program – START

Pass 1 – Pseudo Code • First find starting address of program – START instruction. Its operand will be the starting address

Pass 1 – Pseudo Code contd • Whenever we find a label, save it

Pass 1 – Pseudo Code contd • Whenever we find a label, save it in the symbol table. • Skip over the rest of the program. Set the error flag if an Unrecognized opcode is found.

Pass 2 – Pseudo Code • Write the Header

Pass 2 – Pseudo Code • Write the Header

Pass 2 – Pseudo Code contd • Note • Each text record has a

Pass 2 – Pseudo Code contd • Note • Each text record has a certain length (68). If the assembled instruction cannot be fit into the current text record, a new one is created. • For unrecognized symbols, we set the error flag.