Lab 6

Show a signed maximum on the red LEDs

Computer Organization · Lab 6, Part II · Nios V C

Replace the terminal output from Part I with one memory-mapped store. You will read the answer from ten physical LEDs, then measure how the choice of output changes your program's machine code.

Lab setup

Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser

Where to buildNios V C IDE
  1. Get the starterDownload main.c
  2. Open the Nios V C IDEOpen the lab LabsLand asks you to sign in. Use the access your course or institution provides.
  3. Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.

Starter files · C

Try this activity in the CPUlator simulator

CPUlator simulator

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.

Predict the ten simulated red LEDs when the starter processes {5, −12, 4, 17, −3, 5}. Read LEDR9 on the left and LEDR0 on the right. Complete the signed comparison loop and repeat. Replace the list with {4, −11, −7, −18, −7}, then rebuild. Record each ten-bit pattern, decode its signed value, and explain which ten bits of the 32-bit result the volatile store preserves. Compare these predictions with the physical camera when you run the board worksheet.

Adapted from FPGAcademy Computer Organization 24.1, Lab 6, Part II. Programs, input lists and remote procedure by LabsLand. Original handout · MIT notice

Predict the light pattern

The starter contains a count followed by five signed values. Circle the largest data value. Convert it to ten bits. Label your drawing from LEDR9 on the left to LEDR0 on the right. Repeat with the list {4, −11, −7, −18, −7}. For a negative result, display the low ten bits of its two's-complement representation.

Build and observe

Open the DE1-SoC Nios V C editor and put the starter in main.c. Finish the signed comparison loop. The volatile store writes the answer to the LED data register at 0xff200000. Build the ELF, upload it and read the row of red LEDs from the board camera. Rebuild with the negative list. Record both readings and explain how you recovered the signed answer in the second run.

Input Prediction (10 bits) Observed LEDR9…0 Signed result
Mixed list
Negative list

Compare executable code

Build two versions from the same corrected source using the same RISC-V toolchain, startup, linker script and optimization. Keep the volatile input list identical. In the first version replace the LED store with a printf that prints best using %d and includes a newline. In the second keep the LED store. Use riscv32-unknown-elf-size on the two uncompressed ELF files and compare the text column. If doing this step with a local course toolchain, record its version. Explain the cost of formatted output and why the length of a compressed download cannot answer the question.

The activity ZIP contains the LabsLand runtime and compare.py in de1-runtime. Save the two versions as led.c and print.c. Run python3 de1-runtime/compare.py led.c print.c in a terminal with the RISC-V tools on your path. If your compiler is riscv-none-elf-gcc, add --prefix riscv-none-elf-. Include stdio.h in the printf version.

Hand in

Submit two LED readings, the two text-section sizes in bytes, the build options, and one explanation of the difference.

Adapted from FPGAcademy Computer Organization 24.1, Lab 6, Part II. Programs, input lists and remote procedure by LabsLand. Original handout · MIT notice