Lab 6

Measure bit runs and display three decimal results

Debugger setup

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

  1. Get the sourceDownload main.c
  2. Open the simulatorOpen CPUlator

Computer Organization · Lab 6, Part III · Nios V C

A stream of binary data can contain long stretches of the same bit or an alternating pattern. Find the longest run of each kind within a single 32-bit word. Your program must show its three results simultaneously on the simulated displays.

Work one word by hand

Write 0x80000001 as 32 binary digits. Count the longest run of ones, of zeros and of alternating bits. A single bit counts as an alternating run of length one. Adjacent words in the array are separate measurements. What would happen if a run could cross the boundary?

Implement the measurement

In CPUlator, select C in the Language menu. Open the starter main.c with File → Open. Choose Compile and Load (F5), then Continue (F3). Find Seven-segment displays in Devices. What does the unfinished program show? Complete measure. Process exactly 32 bits for each unsigned word, including its leading zeros. Reset the current lengths when you start a new word and retain the three maxima for the entire array. You can scan the bits or apply repeated shifts and masks. The starter handles decimal conversion and the display registers.

The display is read from left to right in pairs. HEX5–4 show alternating bits, HEX3–2 show zeros and HEX1–0 show ones. Write each pair with two decimal digits. The DE1-SoC Computer peripheral uses a set bit to illuminate a segment.

Read the simulated displays

Use Compile and Load and then Continue after each edit. For each new array, predict all six digits before rebuilding. Read the six rightmost displays. The two unused positions on their left remain dark. Enter a zero word as real data in the last trial. Use an explicit word count so the zero cannot stop the scan early.

Words in the array Predicted HEX5…0 Observed HEX5…0
0xfffffff0, 0x80000001, 0x33333333
Same array plus 0xaaaaaaaa
Same array plus 0xaaaaaaaa and 0x00000000

Hand in

Submit your code, the three pairs of predicted and observed readings, and the word responsible for each maximum in the last run. Explain what mistake would give a zero count for a completely zero word.

Adapted from FPGAcademy Computer Organization 24.1, Lab 6, Part III. Programs and test arrays by LabsLand. Original handout · MIT notice

Run a signed maximum on a physical Nios V board