Lab 3

Time a hexadecimal counter with an instruction loop

Debugger setup

CPUlator simulatorRISC-V · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.

  1. Get the sourceDownload loop_counter.s
  2. Open the simulatorOpen CPUlator

How long does a loop take on the processor in your browser? Make HEX1 and HEX0 count from 00 to FF, then return to 00. A short press on KEY0 pauses the count. The next press resumes it.

Design and calibrate

Open loop_counter.s in CPUlator's RISC-V DE1-SoC editor. The display table maps a hexadecimal digit to illuminated segments. Find the instruction that limits the counter to four bits and change its mask so that it retains a full byte. Compile and load, step once, then continue. Use the rightmost two digits of Seven-segment displays.

Time five successive display changes and divide the elapsed time by five. The starter uses 20,000,000 loop iterations. Make a prediction before doubling that count. Record both measured intervals. A browser instruction loop is a useful timing experiment; calibrate it on the machine where you take the measurement.

Test wrap and a short press

Change the initial byte from 0 to 254 (FE hex), compile and reload. Record the first four values. While the counter runs, briefly check and uncheck button 0 in the Push buttons panel. Hold off for at least two expected changes, then press and release again. Record the value held and the first value after resuming.

Delay iterations Time for five changes Seconds per change First four values from FE
20,000,000
40,000,000

Explain why polling the button's current level only after a long loop can miss a press. Identify the load that reads the captured edge and the store that acknowledges it. Restore the initial value and delay before submitting your table.

Adapted from FPGAcademy Computer Organization 24.1, Lab 3, Part III. LabsLand wrote the assembly and activities. MIT notice

Run a signed maximum on a physical Nios V board