There is no checkoff for lab this week. This is primarily practice for the midterm.
By this point, you should be comfortable converting between the standard decimal/hexadecimal/binary representations for numbers. Now, let’s try writing a generic number representation converter for unsigned numbers in C! In particular, you will be filling out two functions in
numberrep.c. Note that the strategy that
numberrep.c uses to convert between different bases is to first convert to decimal and then convert to the new base. This is not necessarily the best way to convert between two numbers. (What might be a better strategy for converting from hex to binary or vice versa?)
Finish the implementations of the functions in
make check should run without any Assertion errors in the output.
Now that you’ve implemented the number representation converter in
C, let’s implement a subset of the program in RISC-V. Specifically, we will be implementing the
validate_number function from the program. The starter code is in
numberrep.s, which already contains the code for
validate_number_char. You can click this magic link to load Venus with the starter code.
The general strategy for
validate_number is to loop through the number and call
validate_number_char each time with a character and a base as arguments. Note that since it is calling a function, you must follow the CALLEE/CALLER conventions for whichever registers you choose to use.
Your implementation of
validate_number should set
a0 to be
1 if the number is valid in this base or
0 if it isn’t. The starter code prints out the value of
a0 for testing purposes.
validate_number_char does and write down your interpretation. Then, finish the implementation of