From bdd08c6c5bc03a38040e426e8e0ba866276549a8 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Wed, 19 Feb 2020 14:11:57 -0500 Subject: [PATCH] Fix bug when generating single-source instructions Single-source instructions need their source spec to be in the the top 4 bits of the source/dest spec, and it was incorrectly being set in the bottom 4 bits. This affected jump instructions, as they would be reading the instruction at the given address rather than jumping to it. Signed-off-by: Alek Ratzloff --- src/vm/obj/assemble.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vm/obj/assemble.rs b/src/vm/obj/assemble.rs index b59a352..9345eac 100644 --- a/src/vm/obj/assemble.rs +++ b/src/vm/obj/assemble.rs @@ -226,13 +226,16 @@ impl Assemble for Inst { let mut bytes = Vec::with_capacity(len); bytes.write_u16::($op).unwrap(); let source = $source; - let source_encoding = source.source_encoding(); + let source_encoding = source.source_encoding() << 4; bytes.write_u8(source_encoding).unwrap(); bytes.extend(source.assemble(asm)?); assert_eq!( - self.len(), bytes.len(), + self.len(), + bytes.len(), "instruction size mismatch in {} instruction - {:?} produces these bytes {:?}", - stringify!($op), self, bytes + stringify!($op), + self, + bytes ); Ok(bytes) }};