Lab 2

Measure an alternating bit pattern

Debugger setup

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

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

Complete alt in alt.s. A run can start with either zero or one. Count bits in the run. For example, 1010 contains four alternating bits and three transitions.

Build a transition mask

Compare neighboring bits with XOR. A word of 32 bits has only 31 neighboring pairs. Sketch the mask for an eight-bit example before extending it to a full word. Decide what to do with the bit that has no higher neighbor. A word with no transitions still has a run of length one.

Test 0xaaaaaaaa and 0x55555555 separately. Inspect the mask and compare the two answers. Include a solid word of all ones and the supplied list. Record the per-word return in a0 and final list maximum in s0. Hand in a counterexample for an implementation that counts a transition beyond bit 31.

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

Run a signed maximum on a physical Nios V board