diff options
author | iximeow <me@iximeow.net> | 2020-02-03 00:25:18 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-02-03 00:25:18 -0800 |
commit | 301cec3455f72f6290717b83046778eb2c847b70 (patch) | |
tree | 8a5331a19c7cea14461424af3c4b1592fa934027 | |
parent | 6d184b08460452619dfffda282db6c713c78a6dc (diff) |
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.
-rw-r--r-- | src/lib.rs | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -1056,6 +1056,20 @@ fn decode<T: Iterator<Item=u8>>(_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 | |