CSCE 611 Fall 2026 Lecture 3: RISC-V ISA 2
Overview
Jason D. Bakos reviews the RISC-V instruction subset for CSCE 611 labs, then develops the Q18.14 fixed-point square-root algorithm students will test in RARS before deploying it on an FPGA CPU. The lecture explains 64-bit multiplication and cross-register shifting, binary-search convergence, switch and display scaling, and practical input constraints that make tested software essential before hardware integration.
Key takeaways
- Q18.14 multiplication produces 28 fractional bits, so restoring a 14-bit fractional format requires a 14-bit right shift across the combined 64-bit product, implemented with two shifts and an OR.
- Binary search provides a square-root method using only multiplication and comparisons, making it suitable for the course CPU without division hardware.
- The 18 FPGA switches encode an integer; shifting their value left by 14 converts it to Q18.14, and the same scale factor converts displayed raw results back to real numbers.
- RARS’s signed 32-bit input limit requires entering upper-half unsigned raw values as R − 2³², especially for switch inputs of at least 2¹⁷ after Q18.14 scaling.
- Testing the fixed-point program in RARS before integrating it with the FPGA CPU makes later failures easier to attribute to hardware rather than unverified software.
Chapters
- The CPU labs focus on six instruction categories: register operations, immediate operations, branches and jumps, loads and stores, and coprocessor instructions.
- Register operations include arithmetic, AND/OR/XOR, shifts, and comparisons; RISC-V branches also provide signed and unsigned comparisons directly.
- Students should restrict Lab 1 code to the listed supported subset so the program can later run on the CPU built in Labs 3 and 4.
- RISC-V MUL returns the low 32 bits of a product, while high-product variants provide upper bits for signed or unsigned multiplication.
- Branch comparisons include equality, inequality, and signed or unsigned greater-than-or-equal and less-than; reversed operands can express less-than-or-equal conditions.
- An unconditional jump pseudoinstruction such as `j` assembles as `jal x0, target`, discarding the return address; `jal` defaults to `x1` when a link register is needed.
- Most RISC-V immediate instructions use a signed 12-bit value, from −2048 through 2047.
- The U-type `lui` instruction places a 20-bit immediate in a register’s upper bits; an additional instruction supplies the low portion of a larger constant.
- RARS expands large-constant pseudoinstructions into multiple machine instructions, illustrating how a value such as 429,496,730 cannot fit in one 12-bit immediate.
- Fixed point represents fractions with integers and an implied scale of 2⁻ᶠ, where f is the number of fractional bits; two fractional bits, for example, scale an integer by one quarter.
- Addition and subtraction require operands to use the same fractional-bit format, while multiplication adds the operands’ fractional-bit counts.
- Lab 1 uses 14 fractional bits, so squaring a value in that format produces 28 fractional bits and requires rescaling.
- Multiplying two 32-bit operands can produce a 64-bit result; RISC-V combines `mul` with a high-product instruction to recover both halves.
- Bakos demonstrates fixed-point decimal-digit extraction by multiplying by a 32-fractional-bit representation of 0.1, then rescaling the fractional remainder by 10.
- The example is assembled and run in RARS; entering 4567 produces the reversed digits 7654, and a large constant is visibly expanded into multiple instructions.
- The FPGA calculator uses Q18.14: 18 whole-number bits and 14 fractional bits in a 32-bit value.
- Squaring a Q18.14 value yields 28 fractional bits across the 64-bit product, so the result must shift right by 14 places to restore the desired format.
- Because RISC-V operates on 32-bit registers, the cross-register shift is assembled with three operations: shift the low half right 14, shift the high half left 18, then OR the pieces together.
- The square-root routine searches for x such that x² matches the input, avoiding Newton–Raphson because the teaching CPU does not implement division.
- It compares each squared guess with the input, adjusts the guess up or down, and halves the step size after each iteration.
- With 14 fractional bits, the representable resolution is 2⁻¹⁴, approximately 1/16,384; some inputs reach an exact zero error while others stop at the format’s precision limit.
- The board’s 18 switches provide an integer input, while the square-root routine uses a 32-bit Q18.14 value internally.
- The program shifts the switch value left by 14 bits to create the fixed-point input; the hex displays can show the fractional result.
- For RARS testing, an actual input such as 5.5 must be encoded by multiplying it by 2¹⁴; decode an output by dividing its raw value by 2¹⁴.
- Bakos recommends a downloadable spreadsheet that traces each binary-search guess, its square, the error, and decimal and hexadecimal raw values.
- The search begins with guess zero and a step of 256, half the approximate maximum root of 512 for an 18-bit switch input.
- Lab test cases pair the raw integer entered in RARS with the expected raw result; inputs such as zero and 16,384 test square roots of 0 and 1 respectively.
- RARS’s integer-input system call accepts signed 32-bit values, so raw values above 2³¹−1 cannot be entered as positive decimal integers.
- For a desired unsigned raw value R in the upper half of the 32-bit range, enter R − 2³² instead; the resulting bit pattern is the intended unsigned value.
- The constraint appears when an 18-bit switch input is shifted left by 14: inputs at or above 2¹⁷ produce raw values whose top bit is set.
- Lab 1’s tested square-root program becomes part of the later CPU test suite, separating software defects from hardware defects during integration.
- The course provides a modified RARS build with support for its custom CSRRW-based I/O instructions; stock GitHub RARS may not recognize those instructions.
- On Linux, launch the downloaded Java archive with `java -jar` and the RARS filename; RARS is also available for Windows and macOS.
Transcript excerpt
0:00 Uh so just to briefly recap uh last lecture I went through all of the uh instructions that almost all the instructions that we're going to be implementing on our CPU and that you need for lab one. Okay. Uh was there any questions about that? So we have our three register RT type instructions. Arithmetic logical shift comparison. So arithmetic is like you know add add subtract logical or your bitwise logical operations like and and or. Uh we will be using those in the lab because you're going to have to use the or instruction to do some bit manipulation for the fixed point. Uh then there's shift instructions. We'll be using those as well in lab in the
0:48 lab. Shifting is when you um change the the position of the bits uh in a register. And then comparison is comparing two values and putting a one or zero in the result uh based on the outcome of the comparison. With MIPS, you would often have to use those comparison instructions. But with risk 5, I don't think you will because risk 5 has a full set of branch branch comparisons. You guys with me? So in my there was no unsigned branch instructions. So you would have to use the unsigned comparison combined with a branch, but in risk they fixed that. So anyway, I going too getting too far in the weeds there, but uh yeah, so uh I've got those listed and I went through uh
1:36 went through the demo that just showed that that program executing. Um then we have the I type. Um there is not you can't assume that there's an I type for every R type. There's a a fairly small number of it type instructions. So, as I mentioned in class, there's no sub
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jason D. Bakos.