Skip to content

Commit

Permalink
o1vm/riscv32im: add example and test for addi
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Dec 23, 2024
1 parent 826c154 commit 1c95861
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Binary file added o1vm/resources/programs/riscv32im/bin/addi
Binary file not shown.
20 changes: 20 additions & 0 deletions o1vm/resources/programs/riscv32im/src/addi.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.section .text
.globl _start

_start:
# Initialize register
li t0, 10 # Load immediate value 10 into t0

# Perform addition
addi t0, t0, 5 # Add 5 to the value in t0 and store the result back in t0

# Custom exit syscall
li a0, 0 # Set a0 to 0
li a1, 0 # Set a1 to 0
li a2, 0 # Set a2 to 0
li a3, 0 # Set a3 to 0
li a4, 0 # Set a4 to 0
li a5, 0 # Set a5 to 0
li a6, 0 # Set a6 to 0
li a7, 42 # Set a7 to 42 (custom ecall number)
ecall
16 changes: 16 additions & 0 deletions o1vm/tests/test_riscv_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ fn test_sll() {
// Expected output of the program
assert_eq!(witness.registers.general_purpose[5], 1 << 14)
}

#[test]
fn test_addi() {
let curr_dir = std::env::current_dir().unwrap();
let path = curr_dir.join(std::path::PathBuf::from(
"resources/programs/riscv32im/bin/addi",
));
let state = o1vm::elf_loader::parse_riscv32(&path).unwrap();
let mut witness = Env::<Fp>::create(PAGE_SIZE.try_into().unwrap(), state);

while !witness.halt {
witness.step();
}

assert_eq!(witness.registers[T0], 15);
}

0 comments on commit 1c95861

Please sign in to comment.