Skip to content

Commit

Permalink
[#201] Fix code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Sep 3, 2021
1 parent e05ee04 commit 948ed1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ByteBuffer generateCode(Program program) {
}

private void writeInstruction(int opcode, long operand) {
int instruction = (int)((operand & 0x1F) | (((opcode & 0x07) << 13)));
code.putInt(NumberUtils.reverseBits(instruction, 32));
int instruction = NumberUtils.reverseBits((int)operand & 0x1F, 32) | ((opcode & 0x07) << 16);
code.putInt(instruction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testCommandLine() throws Exception {

byte[] expected = new byte[33 * 4];
expected[4] = 0x68;
expected[5] = 0x03;
expected[5] = 0x6;
assertArrayEquals(expected, bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,24 @@ public void testCopyrightIsKnown() {
@Test
public void testSTO() throws Exception {
compile("00 STO 22\n");
assertProgram(0x68, 3, 0, 0);
assertProgram(0x68, 0x6, 0, 0);
}

@Test
public void testLDN() throws Exception {
compile("00 LDN 29");
assertProgram(0xB8,2,0,0);
assertProgram(0xB8,0x2,0,0);
}

@Test
public void testSUB() throws Exception {
compile("00 SUB 30");
assertProgram(0x78,4,0,0);
assertProgram(0x78,0x1,0,0);
}

@Test
public void testSTP() throws Exception {
compile("00 STP");
assertProgram(0,7,0,0);
assertProgram(0,0x7,0,0);
}
}

0 comments on commit 948ed1b

Please sign in to comment.