Assembler Computer Organization and Architecture by Ravinder Nath Rajotiya - December 29, 2022January 1, 20230 Share on Facebook Share Send email Mail Print Print Table of Contents Toggle IntroductionCategory or Type of Programming languagesBinary or machine level language:2. Octal or Hex programming language:3. Symbolic Programming language:4. High Level programming language:Translation of the symbolic program into machine language:AssemblerSingle pass assembler:Two-pass Assembler:Que. Explain the pass-1 and pass-2 of the two pass assembler.Pass-1 of a 2-Pass AssemblerPass-2:Write an assembly program for subtracting two numbers. Also show pass-1 and pass-2 procedure for the translation of this program to binary/machine code. Introduction Computer instructions are referenced from Instruction Types here for the purpose of reference. These are used by the assembler while translating the symbolic code to its binary code. Instructions were categorized as MRI Instructions : Direct or indirect memory reference instructions Non-MRI instructions: Instructions does not make a reference to memory, These are register reference or the I/O reference type of instructions. Category or Type of Programming languages Computer or specifically the processor understands and can execute the binary language programs only. Programs written in any other language must be translated to the machine or binary language. The programs may be developed using one of the following types of programming languages: Binary or machine level language: This is the computer natural programming language that is a language of 0’s and 1’s. 2. Octal or Hex programming language: This language has a one-to-one equivalent translation to binary language. Advantage of this language is that it is short notation and easy to write with less chances of typo errors. 3. Symbolic Programming language: This type of language uses symbols constructed using alphabets and digits. It is quite easy to remember and write the programs. However the instructions written using this language, called assembly instructions, must be translated to binary. This translation is done by using a special type of software called as Assembler. Since an assembler is required for the translation to binary such programs are sometimes called as the assembly language programs. 4. High Level programming language: The programs written in this type of programming language hides the lower level details of the hardware. The programmer need not be aware of the computer hardware. Translation of the symbolic program into machine language: Symbolic languages to developed to ease the human effort in developing the programs, but these programs are not understood by the processor. A translator is required to translate such program to their binary equivalent code. Assembler is such a software program that translates the symbolic programs into the binary code. An assembler can be of the following types: Single pass assembler Two-pass assembler Single pass assembler: A single pass assemble will read he program line-by-line and translate it to its machine /or binary code equivalent. Assuming that we have an instruction such as JMP Next ——– ——– Next: The above code is known as the forward reference. The assembler does not where the label next is, it can be short, near or far jump. The assembler has to just guess how far the label Next is located. If the guess is wrong the will lead to inefficient translation and cannot resolve the forward reference issue. So, what is to be done to remove this inefficiency? The answer is to use a two pass assembler. Two-pass Assembler: A two pass assemble scans the program twice, first time to just find how far is the machine code instruction from the symbol. In the second scan process it translates the symbolic code to its machine code. Pass-1 : during pass-1 the assembler scans the whole program line by line and generates a table of symbols called the symbol address table. Pass-2: During the pass-2, a 2-pass assembler scans the whole program again to generate the machine/or the binary code equivalent of the assembly or symbolic program. Que. Explain the pass-1 and pass-2 of the two pass assembler. Pass-1 of a 2-Pass Assembler During pass-1 the assembler scans the whole program one line at a time and generates a table called the symbol address table. This table contains the name of the label and its associated address. Pass-1 uses the pseudo op-table. Operation of pass-1 is explained as follows: Figure- Pass-1 of a 2-pass assembler The assembler initializes the location counter to ‘0’. It then scans a line of code of symbolic program to check if it is a label, ORG or END pseudo op-Code If it is a ORG, it then sets the LC to the value that follows the ORG. If it is a label, the label is saved to a symbol table along with the value of the LC If the symbol read is the pseudo op-code ‘END’ the scanning terminates and the assembler goes to the pass-2 operation. Pass-2: Pass-2 or 2nd pass of the assembler translates the whole code into the binary code. During the pass-2, the assembler makes use of the following database for the translation process. Pseudo instruction table Memory-Reference instruction (MRI) table Non-Memory Reference instruction (MRI) table Symbol address table (generated during pass-1) Tasks performed by the 2-pass assembler during its pass-2 are described below with the help of a flow chart. Figure-pass-2 of a 2-pass assembler, Reference Computer System Architecture by M.Morris Mano (Figure 6.2) Description or the translation process of pass-2 of the assembler Pass-2 Pass-2 of the assembler scans the first line of code and find it as the pseudo instruction. Thus sets the LC to the values given after the ORG. It scans the next line of code to check if it is an instruction of MRI or Non-MRI by referring to the both the tables. If it is MRI instruction then it assigns the bit 12-14 to the 3-bit code and reads the address field and assign it to bit 11-1, It also check if instruction is direct or indirect and sets the bit 15 to ‘0’ or ‘1’ If it is Non-MRI the complete bit-14 to bit-1 along with the mode bit ‘0’ or ‘1’ for register reference or the i/o reference instruction is set in bit-15 and assembled together and stored at the location given by the LC It then increments the LC and repeats the process till the pseudo instruction END is encountered. Write an assembly program for subtracting two numbers. Also show pass-1 and pass-2 procedure for the translation of this program to binary/machine code. Solution: Pass-1: Pass-1 scans the whole code and creates a symbol address table. Figure (a) shows the symbolic program to subtract two numbers, figure (b) gives the steps of pass-1 and figure (c) shows the symbol address table created by pass-1 of the 2-pass assembler. Figure- Process of Pass-1 in creating the Symbol Address Table Pass-2: The pass-2 performs the translation of the symbolic program to its machine or binary code. The steps are: LC is initialized to ‘0’ Pass-2 scans the first line of code and find it as the pseudo instruction. Thus sets the LC to the values given after the ORG. It scans the next line of code to check if it is an instruction of MRI or Non-MRI by referring to the both the tables. If it is MRI instruction then it assigns the bit 12-14 to the 3-bit code and reads the address field and assign it to bit 11-1, It also check if instruction is direct or indirect and sets the bit 15 to ‘0’ or ‘1’ Assembler assembles the three parts and stores the binary code at the location given by the LC, it then increments the LC and repeats the process till the pseudo instruction END is encountered. Instruction 2,5, and 6 are MRI instructions Instruction 3,4,7 are Non-MRI but register reference so their code as seen in the Non-MRI table are set at the address given by the LC 102,103 and 106. The complete listing of the translation code is given below. Figure – Listing of the Translation by Pass-2 of the 2-pass assembler Summary Assembler is a software program that translates the symbolic program code to its machine code format. Pass-1 of the assembler creates the symbol address table Pass-2 of the assembler actually perform the translation into the machine or the binary code. The databases used by pass-2 of the assembler during translation of symbolic program to machine or binary code is given below. Pseudo instruction table Memory-Reference instruction (MRI) table Non-Memory Reference instruction (MRI) table Symbol address table (generated during pass-1) Share on Facebook Share Send email Mail Print Print