Implement SB

This commit is contained in:
2025-12-21 14:24:20 +01:00
parent e910036058
commit eec40b069a
2 changed files with 17 additions and 0 deletions

View File

@@ -53,6 +53,22 @@ pub fn sd(core: &mut Core, instr: Instruction) -> InstructionResult {
}
}
pub fn sb(core: &mut Core, instr: Instruction) -> InstructionResult {
let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_s());
let page = (addr / 4096) as PageNum;
let offset = (addr & (4096 as Addr - 1)) as u16;
let value = core.reg_read(instr.rs2()) as u8;
match core.mem.write_byte(page, offset, value) {
Ok(_) => {
core.pc = core.pc.wrapping_add(4);
InstructionResult::Normal
}
Err(_) => InstructionResult::Exception(()),
}
}
pub fn lui(core: &mut Core, instr: Instruction) -> InstructionResult {
core.reg_write(instr.rd(), instr.imm_u());
core.pc = core.pc.wrapping_add(4);