The purpose of this lab is to give you practical experience working with, and modifying, a microprocessor as described and discussed in class.
Download the microprocessor source code and unpack it (you can use the shell to do this with the command tar xzf processor_v1_verilog.tar.gz). Read through the two PDF documents "Processor Manual" and "Modification Tutorial". This will help familiarize you with how to use the microprocessor on the DE2 board.
Also download the "assembler", extract it using unzip assembler.zip in the Nios II Command Line, and type make within the "assembler" directory created. This will allow you to write a program in code similar to what you are used to. However, this assembler only supports the instructions included in the original processor - once you modify the schematic, you will need to modify the MIF file directly to test your new instructions. To do this, open the MIF file - after the initial commands, you will notice two columns of hex numbers, separated by a colon. The left number is the address, and the right number is the data at that position. Therefore, you can insert the new op-code into your program at the appropriate position by writing it (in hexadecimal) after the appropriate address.
If you open the BDF file in Quartus, you will find that it looks quite similar to the schematic used in class (as it is, in fact, the same processor).
In this lab, you will need to make several different modifications to the processor. It is a good idea to copy the folder several times, so that you can modify the base schematic each time, rather than adding on to previous changes.
To review how to make changes to the processor, you may wish to read an example first - understanding this will make this lab much easier.
In the lab, you will need to modify the processor (the datapath and/or the control) to implement the following instructions:
1. Implement a load indirect (LDIND) instruction. Use opcode 0001 and fields K1 and K2 similar to the existing LOAD. LDIND K1 ((K2)) does the following: K1 = MEM[MEM[K2]] PC = PC + 1 2. Implement a “Jump and Link” (JAL) instruction. JAL takes a single argument which is a 4-bit signed immediate. Its format is similar to the branch instructions. JAL uses the 1110 opcode. It’s function is: K1 = PC + 1 PC = PC + 1 + Sign-Extended(Imm4) 3. Implement a Jump Register instruction. It’s format uses bits 7 and 6 to specify a register, bits 5 and 4 are left unused and the lower four bits are 1100. JR K1 does PC = K1.
You will need to demonstrate that your processor properly supports these instructions in the lab.
Demonstrate that the processor correctly supports the new instructions.
The format of MIF files consists of three part: the header, the body, and the end. For the purpose of this course, we will look only at the body, use the HEADER and END parts as is from the text below.
### HEADER ### DEPTH = 256; WIDTH = 8; ADDRESS_RADIX = HEX; DATA_RADIX = HEX; CONTENT BEGIN ### BODY ### 00 : 10; 01 : 80; 02 : E4; 03 : 24; ... ### END ### END; |
The BODY section contains rows of hexadecimal number pairs seperated by a colon and ending with a semi-colon (i.e. "03 : 24;", "04 : 66;" as seen above). The first number indicates the address where the instruction is to be located, the second number is the encoded opcode for the instruction (i.e. add, subtract, or, etc.).
Before modifying an instruction read the note on instructions encoding.
For example, let us look at an instruction encoding 0x24 ( or b'00100100 ) at address 0x3. Refering to a instruction encoding sheet, this is an addition instruction which sums K0 and K2 and places the result in K0 ( K0 = K0 + K2 ). To modify this instruction into K1 = K1 - K2 (instruction encoding b'01100110 or 0x66 ), we change the encoded instruction 0x24 to 0x66.
before modification -> "03 : 0x24;" after modification -> "03 : 0x66;"
To run your new program perform the following steps:
Replace the file multicycle.qsf with this QSF file (rename it to multicycle.qsf and make sure you close Quartus before doing so), then recompile and program your DE1. You will need to restore the original multicycle.qsf file for demonstration on the lab's DE2s, so keep a copy of it and do the same to get back to the DE2.