Return a maximum from a subroutine
Online version: https://fpga.labsland.com/altera/computer-organization/lab-01/part-03/
Debugger setup
CPUlator simulatorRISC-V · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.
- Get the sourceDownload
largest.s - Open the simulatorOpen CPUlator
Complete large in largest.s. On entry a0 contains the number of words, at least one, and a1 the address of the first word. On return a0 must contain the greatest signed sample. The caller saves it at result. Use temporary registers for scratch values.
Test the interface
Set a breakpoint at large and inspect a0, a1 and ra. Predict the address to which ret will return. Step through the first load and check that its address is word-aligned. Use Step Out to return to the caller. Run the store and inspect result in Memory.
Test the supplied all-negative list, a single sample of −71 and a list whose largest value is last. Update the count every time you change the number of samples. Submit the argument values and observed return for each case. Explain why ret uses ra and why an unsigned comparison would fail on a mixture of signs.
Adapted from FPGAcademy · Computer Organization 24.1 · Lab 1, III. Original LabsLand assembly and worksheet. MIT
