Lokmanya Tilak Jan Kalyan Shikshan Sanshtha’sWorkshop on“Improving Teaching Competencies” Lecture on the Topic: System Programming:Assembler Presented BY : Manoj S. Chaudhari Smt. Bhagwati Charturvedi College of Engg.
Aim of the Lecture: To Study Assembler Structure of Assembly Language Program(ALP) Steps to Translate ALP to Machine Language Program Data Structure/Tables used by the assembler Two pass assembler Pass 1 Assembler Pass 2 Assembler
Assembler: System Programs: Job is done more efficiently. Executes the programs effectively. e.g. Compiler , Interpreter
A system program which translate ALP into its equivalent machine language. It is basically a translator.
Structure of Assembly Language Program: ALP is a sequence of Assembly language statement. Each Assembly language statement consist of 4 fields: Label Opcode Operand Comment Consider the Assembly Language Statement: Loop MVI B, 05H ; move data 05H to register B Label Opcode Operand Comment
Two Types of Opcodes: 1.Pseudo- opcode 2.Machine Opcode
e.g. USING , DC, DS
e.g. ADD, MVI , DCR Types of Opcodes:
Steps for Translating an ALP to Machine Language Code Translation is statement by statement basis . Read the assembly language statement and separate all the fields. Verify whether opcode is Machine opcode or Pseudo opcode. If Pseudo opcode , check the type of Pseudo opcode. If Machine opcode , obtain information about binary code , format and length of instruction. Process the operands. Increment the value of counter by length of the instruction.
Data Structure/Tables used by Assembler: Following are the tables used by the assembler. 1) Machine Opcode Table (MOT) 2)Pseudo Opcode Table (POT) 3)Symbol Table (ST) 4)Base Register Table (BRT) 5)Literal Table (LT)
1)Machine Opcode Table The table consist of the fields: Name of mnemonic i.e. machine opcode, equiv. byte opcode, format of instruction and length of instruction.
2)Pseudo Opcode Table(POT) This table consist of the fields : Name of Pseudo opcode Routine associated with the Pseudo Opcode
3)Symbol Table(ST) The symbol table keeps track of the symbols used in the ALP . It has the following fields . Name of symbol Value of symbol Type of symbol
4)Base Register Table This table keeps the track of registers which are used as base register. The table has the following format.
5)Literal Table The literal table keep list of all the literals used in the program. The table has the following format.
Two Pass Assembler The entire process of translating an ALP to its equivalent machine language code is divided into two passes. 1) Pass 1 Assembler. 2)Pass 2 Assembler.
Pass 1 Assembler The function of Pass 1 Assembler is :
To define and compute the value of symbols .
Assigning and storing the addresses to literals.
So output of pass 1 is Symbol table and Literal table. Processing of Pass 1 with :
1)USING and DROP: No processing is done. 2)EQU: Processed for evaluation of operands.
Contd….. 3)DC/DS: Processed for the allocation of storage and LC is updated. 4)START: LC is incremented by the value of the operand. 5)LTORG: Storage is assigned from the start of the program or from previous LTORG. 6)END : Assembler allocates all the literals before going for pass 2.
Get the length of instruction . If label/literal is present enter it in LT/ST and increment LC .
Pass 1 Data Bases: 1)Input Source Program 2) LC : Used to keep track of each instruction. 3) MOT :Indicates Symbolic mnemonic for each instruction and its length. 4)POT: Indicates Symbolic mnemonic and action to be taken for each Pseudo Opcode. 5)ST: Store each label and its value. 6)LT: Store each literal and its corresponding location. 7)A Copy of input later used by pass2
Pass 1 Assembler Flow Chart: USING DROP Found DC/DS not found EQU END Pass 1 LC0 A Read ALS X SearchPOT? Type of Pseudo Opcode Adjust LC to Proper Alignment E Search MOT Eval Operand field B C D
yes no B C D E Llength LLength of data field Assign value to symbol in Label field Assign Storage Location to Literals Process Literals ,Enter in LT Onto Pass 2 Any Symbol? Assign Current value of LC to Symbol LC=LC+L A Write ALS on file for Use by Pass 2 X
References: Textbook : 1)“System Programming”, By J.J. Donovan. 2)”System programming and Operating system”, By D. M. Dhadhere. 3)”Concepts of Compiler design “,By Adesh K Pandey.