Lab 5

Capture a switch pattern on a button interrupt

Debugger setup

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

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

The main loop copies ten switches to the red LEDs. A separate routine takes a snapshot of the switches when a pushbutton triggers an interrupt. Predict which output will change immediately and which will keep an earlier value.

Trace the two paths

Open interrupt_snapshot.s in CPUlator for the RISC-V DE1-SoC. Locate the store in mirror and the two stores in snapshot_trap. One acknowledges the pushbutton, the other updates the display. Run the starter with switches 1 and 2 on, press and release button 0, and compare the LEDs with HEX0. Correct the display store to write the sampled switch word. Compile and load again.

Action LED word Segment bars on HEX0
Turn on switches 1 and 2
Press and release button 0
Change the switches to bit 6 alone
Press and release button 3
Clear the switches

Step through the interrupt

Stop, reload, and search for snapshot_trap in Disassembly. Click the breakpoint gutter at its first instruction and continue. Briefly toggle a pushbutton in Devices. Read mcause, mepc and sp before stepping. Step into the handler until the stack pointer changes. What does its new value tell you about the stack frame? Find the store to the edge-capture register. Remove the breakpoint, continue and check that changing the switches still updates the red LEDs.

Submit the completed table and the low-order interrupt number decoded from mcause. Explain why the LED loop can continue to use its original registers after mret.

Adapted from FPGAcademy Computer Organization, Lab 5, Part I. LabsLand wrote the assembly and activities. MIT notice

Run a signed maximum on a physical Nios V board