summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-02-03 00:25:18 -0800
committeriximeow <me@iximeow.net>2020-02-03 00:25:18 -0800
commit301cec3455f72f6290717b83046778eb2c847b70 (patch)
tree8a5331a19c7cea14461424af3c4b1592fa934027 /src
parent6d184b08460452619dfffda282db6c713c78a6dc (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.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs14
1 files changed, 14 insertions, 0 deletions
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<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 |