Find a signed maximum on Nios V
Online version: https://fpga.labsland.com/altera/computer-organization/lab-06/part-01/
Computer Organization · Lab 6, Part I · C on the DE1-SoC Computer
You will translate a RISC-V list traversal into C, inspect the generated instructions and run it on a physical Nios V processor. Open Figure 1 of the original handout. Trace the first two loop iterations on paper. Which register counts the words still to inspect? Which register holds the largest data value so far?
Lab setup
Nios V C IDE · DE1-SoC
Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser
Where to buildNios V C IDE- Get the starterDownload
main.c - Open the Nios V C IDEOpen the lab LabsLand asks you to sign in. Use the access your course or institution provides.
- Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.
Starter files · C
Worksheet and starter (.zip) for offline work or printing
Try this activity in the CPUlator simulator
CPUlator simulator
CPUlator: https://cpulator.01xz.net/?sys=rv32-de1soc
Open CPUlator · Download simulator worksheet
In CPUlator choose C in Language. Open main.c with File → Open, choose Compile and Load (F5), then Continue (F3). Keep the count in word zero separate from the signed data that follow.
Before changing the starter, predict the two lines it will print. Find the JTAG UART panel and compare its output with your prediction. Complete largest so that it visits every data element, then rebuild and run again. Move 17 to the final position in the mixed list and repeat. Record the three pairs of results. In Disassembly, go to largest and find the load and branch used to update the maximum. What happens to the negative list if best starts at zero?
Based on FPGAcademy Computer Organization 24.1, Lab 6, Part I. LabsLand wrote the programs, test cases and remote instructions. Original handout · FPGAcademy MIT notice
Predict
Each list begins with a length. That first word is metadata. The remaining words are signed data. Predict both outputs before you run the program.
| List in memory | Your predicted maximum | Reading from the board terminal |
|---|---|---|
| 5, −12, 4, 17, −3, 5 | ||
| 4, −11, −7, −18, −7 |
Build and run
Open the Nios V C editor and put the starter into main.c. It prints two answers but only inspects the first data word in each list. Implement the loop in largest. Use the count when deciding where to stop. Both supplied lists contain at least one data word.
Select Build ELF, then Upload to FPGA. Wait for the board to report that the program is ready. Read the two lines in its Console and complete your table. Move the largest positive value to the last position in the mixed list and run again. Explain what an off-by-one error would print.
Inspect the implementation
Use the GDB or CPUlator instructions in the handout to inspect the RISC-V disassembly at main. Locate a load and the comparison or branch used to update the maximum. If optimization folds a constant example or inlines the function, compile the same source with debug information and optimization disabled for this inspection. Distinguish the startup routine from your C code.
Hand in
Submit your two observed terminal lines, your changed input and result, and a short annotated disassembly excerpt. Explain why starting the maximum at zero gives the wrong answer for the negative list.
Based on FPGAcademy Computer Organization 24.1, Lab 6, Part I. LabsLand wrote the programs, test cases and remote instructions. Original handout · FPGAcademy MIT notice
