Implement SH

This commit is contained in:
2025-12-23 18:31:04 +01:00
parent f38114dbd7
commit 23392a55df
2 changed files with 21 additions and 0 deletions

View File

@@ -86,6 +86,26 @@ pub fn lw(core: &mut Core, instr: Instruction) -> InstructionResult {
}
}
pub fn sh(core: &mut Core, instr: Instruction) -> InstructionResult {
let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_s());
if !addr.is_multiple_of(std::mem::size_of::<HWord>() as Addr) {
return InstructionResult::Exception(());
}
let page = (addr / 4096) as PageNum;
let offset = (addr / 2 & ((4096 / 2 as Addr) - 1)) as u16;
let value = core.reg_read(instr.rs2()) as HWord;
match core.mem.write_hword(page, offset, value) {
Ok(_) => {
core.advance_pc();
InstructionResult::Normal
}
Err(_) => InstructionResult::Exception(()),
}
}
pub fn lh(core: &mut Core, instr: Instruction) -> InstructionResult {
let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_i());