From 301cec3455f72f6290717b83046778eb2c847b70 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 3 Feb 2020 00:25:18 -0800 Subject: popm register list is reversed from pushm order see pages 219 and 215 in `M16C/60, M16C/20, M16C/Tiny Series Software Manual` aka "rej09b0137_m16csm.pdf". this change canonicalizes to pushm order. --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 32baa40..98c53c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1056,6 +1056,20 @@ fn decode>(_decoder: &InstDecoder, inst: &mut Instruction, RegList => { inst.imm_wide = read_imm(bytes, 1)? as u32; inst.length += 1; + + // internally, the register list is given one order. + // however, the m16c encoding specifies reverse order for pushm/popm + // register lists.. so, reverse it here and make it correct for everyone + // else. + if let Opcode::POPM = inst.opcode { + let mut replacement_imm = 0u8; + for i in 0..8 { + if inst.imm_wide & (1 << i) != 0 { + replacement_imm |= 1 << (7 - i); + } + } + inst.imm_wide = replacement_imm as u32; + } }, JmpDisp8 | Disp8 | -- cgit v1.1