$25
Computer Architecture Laboratory
Write an assembler for the ToyRISC ISA.
Input to the Program
1. full path to the assembly program.
2. full path to the object file to be created.
Output of the Program
• the program must create the object file at the specified location.
Broad Outline of the Steps
The mechanism of assembly has already been discussed in class. As an example, consider the assembly of this instruction from assignment 1’s statement: load %x0, $a, %x4 in Table 1.
Table 1: Assembly of load %x0, $a, %x4
Field
Value
Binary Representation
Operation
load
10110
rs1
x0
00000
rd
x4
00100
imm
0
00000000000000000 (recall that ‘a’ refers to address 0)
Full Instruction
10110000000010000000000000000000
= -1341652992 (signed representation)
The task of assembly has been further simplified. We have done the parsing of the assembly program for you (git clone https://gitea.iitdh.ac.in:
443/rajshekar.k/CS311_assignment2.git).
• For all labels, both in data and in code, we have set up the symbol table that maps label to address. To get the address corresponding to a label str, simply call ParsedProgram.symtab.get(str).
• Similarly, instructions are also gathered in a simple array. To access the instruction at a given address addr, simply call ParsedProgram.getInstructionAt(addr).
• Each instruction is represented by an object of the Instruction class (see generic/Instruction). You can get the operation type and the operands by calling the appropriate functions mentioned in this class.
• Each operand is represented by an object of the Operand class (see generic/Operand). You can get (i) the operand type – that is, is it a register operand, an immediate, or a label, and (ii) the value – that is, the register number, the immediate value, or the label string.
You only need to complete the function src.generic.Simulator.simulate().
The expected format of the object file is as follows:
• Header: Here, you simply write the address of the first instruction. This is an integer, and therefore 4 bytes long.
• Data: Here, you write all the static data one after another. Each datum is 4 bytes long.
• Text: Here, you write the encoded instructions one after another. Each instruction is 4 bytes long.
Please see the following example:
. data a
10 b
20 . text
load %x0 , $a , %x4
end
The given assembly file will contain the integers (and not strings!) 2, 10, 20, −1341652992, −402653184. The header consists of the instruction of the first instruction, in this case 2. The two data follow. The binary equivalents of the load and end instructions are then placed.
You may read the file that you create using the xxd command.