Skip to content

Program 8: Byte copy and checksum

Program catalogue · Instruction reference · Executable reference

Purpose

Copy five bytes and compute an unsigned-byte checksum, then store the checksum as a word.

This is an instruction-behavior correctness fixture.

Setup

Property Value
Benchmark workload ID program-08
Headless selection --program 8
Visualizer scenario rv32i-program8
Registered test RV32ISingleCycleSystemTest/program-08
Instruction image 14 words, starting at 0x00000000; last word at 0x00000034
Initial state PC = 0x00000000; all registers zero; neither halted nor trapped
Memories Separate instruction and data memories, 256 KiB each; unlisted data bytes zero
Start address Bytes, in increasing address order
0x00000100 01 02 03 04
0x00000104 FF

The table lists the complete preloaded data image, not instruction bytes. Data values use little-endian byte order.

Register Role established by the program
x1 Next source byte
x2 Next destination byte
x3 Remaining byte count
x4 Checksum
x5 Loaded unsigned byte
x6 Checksum output address 0x160

The shared setup describes reset, loading, and the behavioral-core selection. These hand-written programs do not use the standard ABI stack.

Assembly

Every instruction word is shown, including words that a trap or branch may prevent from executing. Address and word comments identify the exact fixture image.

addi x1, x0, 0x100             # 0x00000000 | 0x10000093
addi x2, x0, 0x140             # 0x00000004 | 0x14000113
addi x3, x0, 5                 # 0x00000008 | 0x00500193
addi x4, x0, 0                 # 0x0000000C | 0x00000213
copy_loop:
lbu x5, 0(x1)                  # 0x00000010 | 0x0000C283
sb x5, 0(x2)                   # 0x00000014 | 0x00510023
add x4, x4, x5                 # 0x00000018 | 0x00520233
addi x1, x1, 1                 # 0x0000001C | 0x00108093
addi x2, x2, 1                 # 0x00000020 | 0x00110113
addi x3, x3, -1                # 0x00000024 | 0xFFF18193
bne x3, x0, copy_loop          # 0x00000028 | 0xFE0194E3
addi x6, x0, 0x160             # 0x0000002C | 0x16000313
sw x4, 0(x6)                   # 0x00000030 | 0x00432023
ebreak                         # 0x00000034 | 0x00100073

Execution

  1. Initialize source 0x100, destination 0x140, count five, and checksum zero.
  2. Each iteration uses LBU to read one byte, SB to copy it, and ADD to include its unsigned value in the checksum. Both pointers advance by one byte.
  3. The final input byte is 0xFF. LBU contributes 255, not -1; the checksum is 1 + 2 + 3 + 4 + 255 = 265 = 0x109.
  4. After five iterations, store the checksum at 0x160 and halt. The total is 4 + 5 × 7 + 3 = 42 attempts.

Expected result

These are the fixture's explicit final-state assertions. Unlisted registers are not implicitly zero; their values follow the assembly. The store table enumerates every written byte, including zero-valued writes.

Item Expected value Meaning
x1 0x00000105 Next source byte
x2 0x00000145 Next destination byte
x3 0x00000000 Remaining byte count
x4 0x00000109 Checksum
PC 0x00000034 EBREAK address
Attempts 42 Checkpoints I0–I41
HALTED 1 Project halt
TRAPPED 0 No exception
TRAP_CAUSE 0 None, a project enum code
Start address Bytes, in increasing address order
0x00000140 01 02 03 04
0x00000144 FF
0x00000160 09 01 00 00

All data bytes not listed as written retain their initial values. The destination bytes are 01 02 03 04 FF; the checksum is the little-endian word 0x00000109.

Simulation and checkpoints

For a headless functional check, run build/rv32i_experiment --core single --program 8 --period 4000 --max-cycles 4096 --allocation-limit-mib 512. Select baseline or advanced for the same fixture on another core; add --fidelity reference for the structural-datapath reference profile. The explicit period is a scheduling choice, not a performance result. Use the campaign procedure for clock-certified measurements.

All 42 instruction attempts are included, with absolute simulator time and checkpoint number. The terminating EBREAK is included. The table is scrollable in both directions. Observation conventions distinguish these attempts from loaded word addresses and hardware cycles.

All 42 instruction-attempt checkpoints of RV32ISingleCycleSystemTest/program-08, with a behavioral core. Times are absolute simulator units, not milliseconds or an ISA latency.

CheckpointTimeInstruction / addressExpected architectural effects
I07080ADDI @ 0x00000000raw=0x10000093, pc_after=0x00000004, wb=x1=0x00000100, mem=None, flow=next
I111080ADDI @ 0x00000004raw=0x14000113, pc_after=0x00000008, wb=x2=0x00000140, mem=None, flow=next
I215080ADDI @ 0x00000008raw=0x00500193, pc_after=0x0000000c, wb=x3=0x00000005, mem=None, flow=next
I319080ADDI @ 0x0000000craw=0x00000213, pc_after=0x00000010, wb=x4=0x00000000, mem=None, flow=next
I423080LBU @ 0x00000010raw=0x0000c283, pc_after=0x00000014, wb=x5=0x00000001, mem=Read Byte @0x00000100 -> 0x00000001, flow=next
I527080SB @ 0x00000014raw=0x00510023, pc_after=0x00000018, wb=None, mem=Write Byte @0x00000140 <- 0x00000001, flow=next
I631080ADD @ 0x00000018raw=0x00520233, pc_after=0x0000001c, wb=x4=0x00000001, mem=None, flow=next
I735080ADDI @ 0x0000001craw=0x00108093, pc_after=0x00000020, wb=x1=0x00000101, mem=None, flow=next
I839080ADDI @ 0x00000020raw=0x00110113, pc_after=0x00000024, wb=x2=0x00000141, mem=None, flow=next
I943080ADDI @ 0x00000024raw=0xfff18193, pc_after=0x00000028, wb=x3=0x00000004, mem=None, flow=next
I1047080BNE @ 0x00000028raw=0xfe0194e3, pc_after=0x00000010, wb=None, mem=None, branch=BNE taken=true
I1151080LBU @ 0x00000010raw=0x0000c283, pc_after=0x00000014, wb=x5=0x00000002, mem=Read Byte @0x00000101 -> 0x00000002, flow=next
I1255080SB @ 0x00000014raw=0x00510023, pc_after=0x00000018, wb=None, mem=Write Byte @0x00000141 <- 0x00000002, flow=next
I1359080ADD @ 0x00000018raw=0x00520233, pc_after=0x0000001c, wb=x4=0x00000003, mem=None, flow=next
I1463080ADDI @ 0x0000001craw=0x00108093, pc_after=0x00000020, wb=x1=0x00000102, mem=None, flow=next
I1567080ADDI @ 0x00000020raw=0x00110113, pc_after=0x00000024, wb=x2=0x00000142, mem=None, flow=next
I1671080ADDI @ 0x00000024raw=0xfff18193, pc_after=0x00000028, wb=x3=0x00000003, mem=None, flow=next
I1775080BNE @ 0x00000028raw=0xfe0194e3, pc_after=0x00000010, wb=None, mem=None, branch=BNE taken=true
I1879080LBU @ 0x00000010raw=0x0000c283, pc_after=0x00000014, wb=x5=0x00000003, mem=Read Byte @0x00000102 -> 0x00000003, flow=next
I1983080SB @ 0x00000014raw=0x00510023, pc_after=0x00000018, wb=None, mem=Write Byte @0x00000142 <- 0x00000003, flow=next
I2087080ADD @ 0x00000018raw=0x00520233, pc_after=0x0000001c, wb=x4=0x00000006, mem=None, flow=next
I2191080ADDI @ 0x0000001craw=0x00108093, pc_after=0x00000020, wb=x1=0x00000103, mem=None, flow=next
I2295080ADDI @ 0x00000020raw=0x00110113, pc_after=0x00000024, wb=x2=0x00000143, mem=None, flow=next
I2399080ADDI @ 0x00000024raw=0xfff18193, pc_after=0x00000028, wb=x3=0x00000002, mem=None, flow=next
I24103080BNE @ 0x00000028raw=0xfe0194e3, pc_after=0x00000010, wb=None, mem=None, branch=BNE taken=true
I25107080LBU @ 0x00000010raw=0x0000c283, pc_after=0x00000014, wb=x5=0x00000004, mem=Read Byte @0x00000103 -> 0x00000004, flow=next
I26111080SB @ 0x00000014raw=0x00510023, pc_after=0x00000018, wb=None, mem=Write Byte @0x00000143 <- 0x00000004, flow=next
I27115080ADD @ 0x00000018raw=0x00520233, pc_after=0x0000001c, wb=x4=0x0000000a, mem=None, flow=next
I28119080ADDI @ 0x0000001craw=0x00108093, pc_after=0x00000020, wb=x1=0x00000104, mem=None, flow=next
I29123080ADDI @ 0x00000020raw=0x00110113, pc_after=0x00000024, wb=x2=0x00000144, mem=None, flow=next
I30127080ADDI @ 0x00000024raw=0xfff18193, pc_after=0x00000028, wb=x3=0x00000001, mem=None, flow=next
I31131080BNE @ 0x00000028raw=0xfe0194e3, pc_after=0x00000010, wb=None, mem=None, branch=BNE taken=true
I32135080LBU @ 0x00000010raw=0x0000c283, pc_after=0x00000014, wb=x5=0x000000ff, mem=Read Byte @0x00000104 -> 0x000000ff, flow=next
I33139080SB @ 0x00000014raw=0x00510023, pc_after=0x00000018, wb=None, mem=Write Byte @0x00000144 <- 0x000000ff, flow=next
I34143080ADD @ 0x00000018raw=0x00520233, pc_after=0x0000001c, wb=x4=0x00000109, mem=None, flow=next
I35147080ADDI @ 0x0000001craw=0x00108093, pc_after=0x00000020, wb=x1=0x00000105, mem=None, flow=next
I36151080ADDI @ 0x00000020raw=0x00110113, pc_after=0x00000024, wb=x2=0x00000145, mem=None, flow=next
I37155080ADDI @ 0x00000024raw=0xfff18193, pc_after=0x00000028, wb=x3=0x00000000, mem=None, flow=next
I38159080BNE @ 0x00000028raw=0xfe0194e3, pc_after=0x0000002c, wb=None, mem=None, branch=BNE taken=false
I39163080ADDI @ 0x0000002craw=0x16000313, pc_after=0x00000030, wb=x6=0x00000160, mem=None, flow=next
I40167080SW @ 0x00000030raw=0x00432023, pc_after=0x00000034, wb=None, mem=Write Word @0x00000160 <- 0x00000109, flow=next
I41171080EBREAK @ 0x00000034raw=0x00100073, pc_after=0x00000034, wb=None, mem=None, flow=next, halted=true

Open program 8 reference