Generate machine language - Translate mnemonic operation codes to machine code
Assign addresses to symbolic labels used by the programmer
Generate an image of what memory must look like for the program to be executed. Generate an image of what memory must look like for the program to be executed. Interpret assembler directives (Pseudo-Instructions)
Input Assembly Code Output - Assembly Listing
- Object Code
Intermediate files - Assembly Listing
- LOCCTR
- Instruction Length
- Error Flags
Two Passes: Intermediate files
The main problem is forward reference. The main problem is forward reference. Eliminating forward reference - Simply ask the programmer to define variables before using them.
However, ?! - Backward jumps is too restrictive.
- Forward jumps (Subroutine calls, Loops)
For any symbol that has not yet been defined For any symbol that has not yet been defined - 1. omit the address translation
- 2. insert the symbol into SYMTAB, and mark this symbol undefined
- 3. the address that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry
- 4. when the definition for a symbol is encountered, the proper address for the symbol is then inserted into any instructions previous generated according to the forward reference list
At the end of the program - any SYMTAB entries that are still marked with * indicate undefined symbols
- search SYMTAB for the symbol named in the END statement and jump to this location to begin execution
The actual starting address must be specified at assembly time
Pass 1 - Validate Opcodes
- Assign addresses to all statements in the program
- Scan the source for labels and save their values
- Perform some processing of assembler directives
- Determine the length of areas defined by DC, DS
Pass 2 - Translate/assemble the instructions
- Generate Data Values defined by DC
- Process the rest of the assembler directives
- Write the Object Code and Assembly Listing
Operation Code Table (OPTAB) Operation Code Table (OPTAB) - Opcode, Instruction format, and length
- Pass 1: Validate opcodes
- Pass2: Assemble instructions
Symbol Table (SYMTAB) - Label name and value, error flags
- Pass 1: Created!
- Lookup symbols to insert in assembled instr.
Location Counter - Initialed to the Org or End
OPTAB is static (access) OPTAB is static (access) SYMTAB (add, access) - Insertion and Retrieval efficiency
- Key: Label Name
- LOOP1, LOOP2, LOOP3…, A, X, Y, Z…
Content - The mapping between mnemonic and machine code. Also include the instruction format, available addressing modes, and length information.
Characteristic - Static table. The content will never change.
Implementation - Array or hash table. Because the content will never change, we can optimize its search speed.
In pass 1, OPTAB is used to look up and validate mnemonics in the source program. In pass 2, OPTAB is used to translate mnemonics to machine instructions.
Content Content - Include the label name and value (address) for each label in the source program.
- Include type and length information (e.g., int64)
- With flag to indicate errors (e.g., a symbol defined in two places)
Characteristic - Dynamic table (I.e., symbols may be inserted, deleted, or searched in the table)
Implementation - Hash table can be used to speed up search
- Because variable names may be very similar (e.g., LOOP1, LOOP2), the selected hash function must perform well with such non-random keys.
Dostları ilə paylaş: |