Lab 4

Read a live register with the board controls

Debugger setup

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

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

In CPUlator, SW selects a saved register from s0 to s11. Releasing KEY0 prints its current value in hexadecimal. Releasing any other KEY prints it in decimal. The example initializes the twelve registers with distinct values. The I/O loop and terminal routines are supplied.

Check your terminal before debugging

Download the hexadecimal checkpoint and the decimal checkpoint. Each runs a formatter from an earlier part. In CPUlator choose File → Load ELF…, select one file and press Continue. Look for Sample = 0x00B30E04 or Sample = 11734532 in the JTAG UART. Press Stop before loading the other file.

Both files print the same number. Once you can see both formats, load register_console.s in the Assembly editor and compile it to start your register exercise.

Read the selected register

Complete get_reg. On entry, a0 contains the register number. Save the twelve current values on a 16-byte-aligned stack, index the snapshot by word offset and return the selected value in a0. Restore sp. Identify the bounds check in the caller before you write code.

Select s5, press and release KEY0, then repeat with KEY1. Compare both lines with the s5 value in the Registers pane. Repeat for s0, s10 and s11. Select 12 and press a key. The terminal should keep its previous contents. Select s2 and press again to show that the loop is still running.

Change the initialization of s5 to 0xffffffff and repeat both formats. Submit two pairs of terminal lines, the result of the invalid selection and the stack address used for s11 relative to the snapshot base. Explain why printing hexadecimal must preserve saved registers.

Adapted from FPGAcademy · Computer Organization 24.1 · Lab 4, IV. Original LabsLand assembly and worksheet. MIT

Run a signed maximum on a physical Nios V board