Count consecutive zeros in 32 bits
Online version: https://fpga.labsland.com/altera/computer-organization/lab-02/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
zeros.s - Open the simulatorOpen CPUlator
Complete zeros in zeros.s. Count runs across all 32 positions, including leading and trailing zeros. The caller still treats a zero word as the end of the list. That word does not take part in the maximum.
Predict before stepping
For 0x00001000, count the zeros on both sides of the one. Predict the result for 0x80000007. How can complementing the input let you reuse the shrinking loop? At zeros, record the argument before complementing it and the value passed to the loop afterward.
Replace the first data word with 0x00000001 and then with 0xffffffff. Distinguish the maximum in s0 across the entire list from the return in a0 for an individual word. Submit both values for each experiment and explain why the sentinel must be tested before calling zeros.
Adapted from FPGAcademy Computer Organization 24.1 · Lab 2, III. Original LabsLand assembly and worksheet. MIT
