Forward References : When one pass assembler constructing the object code, if it finds usage of the variables before the declaration then forward reference problem will occur. To avoid forward reference problem: i) Declare the symbols before using it ii) Use more than one pass assembler(multi pass assembler)
Unit 3 assembler and processor
Assembly Language Prakash Khaire UTU
Assembly Language A programming language that is one step away from machine language. Each assembly language statement is translated into one machine instruction by the assembler. Programmers must be well versed in the computers architecture, and, undocumented assembly language programs are difficult to maintain. It is hardware dependent; there is a different assembly language for each CPU series.
Assembly Language It was introduced in 1952 Helped to overcome machine language programmingDefinition : “A language that allows instructions and storage locations to be represented by letters and symbols instead of numbers is called assembly language or symbolic language”
Assembly Language Model … add r1,r2 sub r2,r3PC cmp r3,r4 ALU bne I1 Registers Memory sub r4,1 I1: jmp I3 …
Assembly Language InstructionsBuilt from two pieces Add R1, R3, 3 Opcode Operands What to do with Where to get the data data and put (ALU operation) the results
Types of OpcodesArithmetic, logical add, sub, mult and, or CmpMemory load/store ld, stControl transfer jmp bne
OperandsEach operand taken from a particular addressing mode:Examples:Register add r1, r2, r3Immediate add r1, r2, 10Indirect mov r1, (r2)Offset mov r1, 10(r3)PC Relative beq 100Reflect processor data pathways
Advantages over Machine LanguageEasier to understand and useEasier to locate and correct errors.Easier to modifyNo worry about addressesEasily relocatableEfficiency of machine language
Limitations of Assembly LanguageMachine DependentKnowledge of hardware requiredMachine level coding
Registers in 8086 CPU There are four general purpose registers AX [divided into AH/AL] – the accumulator register BX [divided into BH/BL] – the base address register CX [divided into CH/CL] – the count register DX [divided into DH/DL] – the data registerOther registers SI – source index register DI – destination index register BP – Base pointer SP – Stack pointer
Registers in 8086 CPU This registers are of 16 bits and divided into two 8 bit registers For Example If AX = 0011000000111001b then AH = 00110000b and AL=001111001b Registers are located in CPU, Segment Registers Used for special purpose pointing at accessible blocks of memory It stores any data Four segment registers during execution CS – Points the segment storing the current program DS – Points the segment where variable are defined ES – Extra Segment register, depends on the usage of coder SS – Points to the segment containing the stack Along with general purpose registers, segment registers work to access any memory value.
Flags FLAG : The FLAG register is the status register in the Intel 8086 microprocessor that contains the current state of the microprocessor. This register is 16 bits wide. carry flag (CF)- indicates a carry after addition or a borrow after subtraction, also indicates error conditions. parity flag (PF)- is a logic “0” for odd parity and a logic “1” for even parity. auxiliary carry flag (AF)- important for BCD addition and subtraction; holds a carry (borrow) after addition (subtraction) between bits position 3 and 4. Only used for DAA and DAS instructions to adjust the value of AL after a BCD addition (subtraction). zero flag (ZF)- indicates that the result of an arithmetic or logic operation is zero. sign flag (SF)- indicates arithmetic sign of the result after an arithmetic operation. overflow flag (OF)- a condition that occurs when signed numbers are added or subtracted. An overflow indicates that the result has exceeded the capacity of the machine.
Offset The offset address in an 8086/8088 is the logical address that the program "thinks about" when it addresses a location in memory. The Execution Unit (EU or CPU) is responsible for generating the offset address. The Bus Interface Unit (BIU), on the other hand, takes the offset address and adds it to four times the selected segment register value in order to determine a real address, which is now 20-bits in length.
Registers in 8086 CPU Programmers access various memory locations on combining BX, SI, DI and BP registers. The value in segment registers[CS, DS, SS,ES] is called “segment” The value in purpose registers [BX, SI, DI, BP] is called “offset” For Example DS contains value 1234h and SI contains the value 7890h it can also be recorded as 1234:7890 Two special purpose registers IP – Instruction Register Flags Register – determines the current state of the processor
Registers in 8086 CPU IP works along with CS register and points to the currently executing instruction Flags register is modified by CPU, while performing mathematical operations
Assembler Design ApproachAssembler generates object code.Role of assembler – Translates the source code into target codeDuring this translation process it uses various table like Machine Opcode Table Symbol table Literal table
Assembler Design ApproachMachine Opcode Table It holds opcode used by the processor for different instructions mnemonics Mnemonic size Opcode Holds various instructions Size of instructions in bytes Size of instructions in bytes
Symbol Table It is data structure used by assmebler It keeps into account attributes of the identifier and other information. Attributes : type, value, scope and address It also performs the function of book keeping. It is composed of multiple word entries in fixed format Name Value Type
One Pass AssemblerDoes everything in one passProblem: How do we handle forward references?Could eliminate forward references easy for data – just define the data areas before they are referenced not easy in code – how do we handle selection or loop statements which have forward jumps?Two types of one pass assemblers: produce object code directly in memory produce object program for later execution
One Pass Assembler Assembler generates object code instructions as it scans source program If an operand symbol has not yet been defined operand address is set to 0 in instruction symbol is entered into the symbol table (unless it is already present) entry is flagged to indicate the symbol is undefined address of instruction is added to list of forward references associated with this symbol When symbol definition is encountered forward reference list is scanned, and proper address is inserted in any instructions previously generated (in memory)
One pass assembler that produces object programs Use the same procedure When the definition of a symbol is encountered if instruction which made the forward reference is still in memory, then fix it if not, the instruction has already been written out in a Text record, so generate a new Text record with the correct operand address (could also use a modification record) The loader will fix up the address field
One pass assembler that produces object programs Problem : Forward Reference It be eliminated by declaring variable before using them However, elimination can’t be done easily because sometimes program needs a forward jump.