A
Consider that we plan to deploy a custom RISC-V processor for a space mission, which requires additional data protection in memory. We have decided to implement a Hamming code with even parity to safeguard our data. For this question, please refer to the parity table shown below.
Please note that in this context, bit 0 is considered the least significant bit (LSB).
See also: What Are Bit Flips And How Are Spacecraft Protected From Them?
Implement a RISC-V function called calc_parity
that takes a 4-byte input in a0
and calculates the parity of its bits. It should return 1 for odd parity or 0 for even parity. For example:
calc_parity
must adhere to the RISC-V calling convention.
- A01 = ?
- A02 = ?
Implement store_nibble
, a RISC-V function that takes four bits of data in a0, encodes them into seven bits (as a byte with 0 in the most significant bit [MSB]), and stores the result at the memory address specified in a1. This function does not return any value. You may assume that calc_parity
has been correctly implemented and adheres to the calling convention, but do not assume any specific implementation details of calc_parity
. Also, you may assume that the most significant 28 bits of the argument in a0 are set to 0.
- A03 = ?
- A04 = ?
- A05 = ?
List all registers that need to be saved in the prologue and restored in the epilogue in order for store_nibble
to follow the calling convention. If there are none, write N/A
. __ A06 __
- A06 = ?
B
Suppose you are tasked with writing a file system in C. The struct file_item
represents either a file or a directory. The data
union can hold either the contents of a file (as a string) or an array of pointers to child file_items
. For the purposes of this question, assume that pointers are 4 bytes in length.
We set X
to the maximum value that does not increase the union size. What is the maximum strlen
of a string we can store in a single file? __ B01 __
- B01 = ?
Write code to create files and directories. Ensure that your code still works even if the input strings are freed later on. Assume that the input strings will fit inside a file_item_data
union.
Your solution should be fully correct, without any memory leaks, and should not include any additional lines.
- B02 = ?
- B03 = ?
C
Consider a 16-bit fixed-point system with 1 sign bit, 5 integer bits, and 10 fraction bits. The 10 fraction bits continue where the integer bits left off, representing , , … , . For example, the bit representation 0b0 01101 1010000000
represents .
In this question, we will compare this fixed-point system to a 16-bit floating-point system that adheres to all IEEE-754 conventions, including denorms, NaNs, etc., with a 5-bit exponent and an exponent bias of -15.
Write in hexadecimal using the 16-bit fixed-point system described above. __ C01 __
- C01 = ?
Write in hexadecimal using the 16-bit floating point system system described above. __ C02 __
- C02 = ?
How many numbers in the range (including 16, excluding 64) can be represented by the fixed-point system described above? __ C03 __
- C03 = ?
D
Suppose we have the following program.
For a RISC architecture (RV32 in particular), our RISC-V compiler generates the following assembly code.
Assume that RISC-V instructions are 4 bytes each. Assume data values are 4 bytes each.
How many bytes is the RISC-V program? __ D01 __
- D01 = ?
Assume a=7 and b=3. How many data bytes are loaded/stored in the RISC program? __ D02 __
- D02 = ?
Suppose we have a simple integer vector-vector addition implementation below.
Complete the above code to make the RISC-V assembly function as described in the comment.
- D03 = ?
- D04 = ?
Next, consider a compiler that unrolls loops and reschedules instructions, assuming the loop operates on an even number of elements in the vectors. Shown below.
- D05 = ?
- D06 = ?
- D07 = ?
- D08 = ?
- D09 = ?
- D10 = ?