Presentation is loading. Please wait.

Presentation is loading. Please wait.

1-30-2007CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.

Similar presentations


Presentation on theme: "1-30-2007CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II."— Presentation transcript:

1 1-30-2007CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II

2 1-30-2007CPS4200 System Programming 2007 Spring 2 2.1.2 Assembler Algorithm and Data structure Two major internal data structures: –OPTAB – Operation Code Table: Look up mnemonic operation codes and translate them to their machine language –SYMTAB - Symbol Table Store addresses values assigned to labels. LOCCTR – Location Counter –A variable used to help in the assignment of addresses.

3 1-30-2007CPS4200 System Programming 2007 Spring 3 2.1.2 Assembler Algorithm and Data structure Pass 1, OPTAB is used to look up and validate operation code in source program. In Pass 2, OPTAB is used to translate the operation codes to machine language. IN SIC/XE, it has instruction of different length, we must search OPTAB in the first pass to find the instruction lengths for incrementing LOCCTR. We must have the information from OPTAB in Pass 2 to tell us which instruction format to use in assembling the instruction, and any peculiarities of the object code instruction.

4 1-30-2007CPS4200 System Programming 2007 Spring 4 2.1.2 Assembler Algorithm and Data structure OPTAB is organized as a hash table, with mnemonic operation code as the key. The symbol table (SYMTAB) includes the name and value (address) for each label in the source program, together with flags to indicate error conditions. –During Pass 1 of the assembler, labels are entered into SYMTAB as they are encountered in the source program, along with their assigned addresses. –During Pass 2, symbols used as operands are looked up in SYMTAB to obtain the addresses to be inserted in the assembled instructions.

5 1-30-2007CPS4200 System Programming 2007 Spring 5 2.1.2 Assembler Algorithm and Data structure –SYMTAB is usually organized as a hash table. –Programmer often selects many labels that have similar characteristics, such as labels that start or end with the same characters ( like LOOP1,LOOP2, LOOPA) or are of the same length (like A X, Y, Z).  non-random keys. –Division of the entire key by a prime table length often gives good result

6 1-30-2007CPS4200 System Programming 2007 Spring 6 2.1.2 Assembler Algorithm and Data structure Pass 1 usually writes an intermediate file that contains each source statement together with its assigned address, error indicators, etc. This file can be used as the input to Pass 2. This working copy of the source program can also be used to retain the results of certain operations that may be performed during Pass 1 such as scanning the operand field for symbols and addressing flags.

7 1-30-2007CPS4200 System Programming 2007 Spring 7 2.1.2 Assembler Algorithm and Data structure Pointers into OPTAB and SYMTAB may be retained for each operation code and symbol used. This avoids the need to repeat many of the table-searching operations. See Figure 2.4(a) and (b). For the logic flow of the two passes of our assembler.


Download ppt "1-30-2007CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II."

Similar presentations


Ads by Google