Collaboration
For assignments in CS 2400, you will complete each of them on your own or solo. However, you may discuss high-level ideas with other students, but any viewing, sharing, copying, or dictating of code is forbidden. If you are worried about whether something violates academic integrity, please post on Ed or contact the instructor.
Setup
If you haven’t already, you should follow the Environment setup.
Once you have the environment setup, you should boot it up, and download the floowing tar file.
curl -o hw8.tar https://www.seas.upenn.edu/~cis2400/current/projects/code/hw8.tar
After downloading the tar file, you should be able to type in the command “ls” in the terminal, or use the file explorer to see the download tar file. Once you confirm that the file is downloaded, run the following command to decompress the files:
tar -xvf hw8.tar
Alternatively, you can download the files directly here:
Instructions
For this assignment, we are asking you to complete a function in C that “decodes” the control signals for all of the RISC-V instructions. You will take as input a uint32_t
(unsigned 32-bit integer) and have to figure out what kind of instruction it is and the control signals for it. You will not have to figure out the immediate values, rs1, rs2 or rd values in this assignment.
This is not a typical programming assignment, it is in some ways like the assignments on canvas in terms of what we are asking you to do, with a little bit of coding. You will have to do some binary operations to decode the 32 bit value, but your code will probably look mostly like a bunch of if statements. Doing the assignment in C also allows the assignment to avoid some of the common complaints about similar assignments in the past
- It did not allow someone to save their progress and return to the quiz without having to re-input each of the signal values.
- If you later changed your mind on an answer or wanted to fix your submission, you had to put in every signal again.
This assignment will also give you more practice with C binary operators and will be built on top of in the next assignment :)
Implementation
There are four files associated with this homework assignment, you will only need to modify decoder.c
to complete this assignemnt. main.c
is provided to give you a way to test/debug your code locally. The other files Makefile
and decoder.h
and should not be modified.
decoder.c
is the main file you will be interacting with this in this assignment. The function decode_isntr()
is the only function you need to modify for this assignment. In this function you will need to decode the 32-bit input variable and properly set a riscv_instr
struct that will need to have it’s fields appropriately set for the instruction type that is passed in to the function. You will only need to set the instrion type field and the control signals fields for the struct.
Your job in this assignment is to add code so that when any 32-bit pattern is passed in, the correct instruction type and control signals are set and returned. If a 32-bit value that is passed in is not one of the instructions covered in class, you should set the type to ILLEGAL_INSTR
and return it, no other values need to be set.
Note that you should set each signal to its corresponding integer value and if a signal doesn’t matter, it should be set to the constant we provided called ANY_SIGNAL
.
decoder.h
is a file that contains the declarations for the enum and struct types used in this assignment. There are comments in this file to document the type. Note that the riscv_instr
struct type is likely the type you will need to look at the most for this assignment.
You are free to write helper functions for this and you may find it particulalry useful, especiall if you split up the deocding to different functions depending on what type of instruction it is (e.g. “J type” instructions, “I type” instrunctions, etc.) To identify which instruction a 32-bit pattern represents, you should probably look at the “opcode”, “funct3” and “funct7” portions of the instruction encoding.
Compiling and Testing
We have provided a sample file for you to run & debug locally. There are also public tests on gradescope that can be used for verifying the correctness of your solutions.
To test that your code compiles, you just need to be in the same directory as your HW8 files in the terminal and type the make
command. If you don’t encounter any errors, then you should see something like this:
$ make
clang-15 -g3 -gdwarf-4 -Wall -o main main.c decoder.o
clang-15 -g3 -gdwarf-4 -Wall -c decoder.c
$
If there were any warnings or errors in the compilation process, it would be printed out there. You can also run modify main.c
to test different inputs and print their values and then run the code by typing in ./main
after compiling your code. main.c
already has some example code to show how you can run your code with the ADDI instruction.
Note that we provide a function for you called print_type()
that you can use to print out the instruciton type. You should not have to modify this function.
Submission
Please submit your decoder.c
to Gradescope