Assemblers
Define A program that translates programs from assembly language to machine language.
Elements: Mnemonic Operations Codes (Mnemonic opcodes): Eliminates: Need to memorize numeric opcodes Enables: Helpful diagnostics Symbolic Operands: Symbolic Names Associated: Data or Instructions Performs: Memory Bindings Data Declarations Declared: Variety of notations Conversions: -5 into (11111010)2
Statement Format [ Label ] <Opcode> <operand spec> [,<operand spec>..] [..] Enclosed Specification is optional Label Symbolic name with memory <operand spec> <symbolic name> [+<displacement>] [<index register>]
Assembly Statements: Imperative Statement Declarative Statement Assembler Statement
Imperative Statement: Indicates: Action to be performed during execution of an assembly statement Translates: Into one Machine Instructions
Declarative Statement: Syntax: [label] DS <constant> [label] DC `<values>’ DS: Reserves Area of Memory and associated with them DC: Constructs Memory words containing constants
Example: DS A DS 1 Reserves a memory area of 1 word and associates with name A. G DS 200 Constructs memory words containing constructs. DC One DC ‘1’ Associates: Name with a memory containing the value ‘1’ Conversions: Different forms Hexadecimal,binary,decimal
Constants Use: Use: Initializes memory words to given values Values: Not protected by Assembler It can be changed by new values into the memory word
Constants Type: An immediate Operands: Literals: Can be used in an assembly statement only if the architecture of the target machine includes the necessary features. Literals:
Design Specification: Identify : Necessary to perform task Design : Suitable data structure to record the information Determine : Processing necessary to obtain and maintain the information Processing necessary to perform the task
(Depends) Assembly Program Synthesis Phase: Assembly Statement: MOVER BREG,ONE ONE: Address of Memory Word (Depends) Source Program MOVER: Machine Operation Code (Depends) Assembly Program Considers Two Data Structures: 1) Symbol Table 2) Mnemonics Table
Symbol Table: (Fields) Name Address Mnemonic Table: (Fields) mnemonic opcode
Pass Structure of Assemblers: Two Pass Translation Single Pass Translation
Two Pass Translation Can handle forward references easily 1st Pass: LC processing, symbols entered in the symbol table Symbols defined in the program are entered Performs: Analysis of Source Program 2nd Pass: Synthesizes the target form using the address information found in the information table Performs: Synthesis of Target Program The first pass constructs an intermediate representation of the source Program for use by the second pass.
Design of a Two Pass Assembler Pass I : 1. Separate the Symbol, mnemonic opcode and operand fields 2. Build the Symbol table 3. Perform LC Processing 4. Construct Intermediate Representations Pass 2 : Synthesize the target Program
Advanced Assembler Directives: ORIGIN <address spec> <symbol> EQU <address spec> ORIGIN <address spec> <address spec> or <constants>s ORIGIN statement is useful when the target program does not consist of consecutive memory words <address spec> in the ORIGIN statement provides the ability to perform LC processing in a relative rather than absolute manner.
EQU <symbol> EQU <address spec> where <address spec> is an <operand spec> or <constant> EQU Defines the symbol to represent <address spec> EQU Associates the name <symbol> with <address spec>