diff --git a/riscemu/CPU.py b/riscemu/CPU.py index 5f43cf9..d0ab25e 100644 --- a/riscemu/CPU.py +++ b/riscemu/CPU.py @@ -143,7 +143,14 @@ class CPU: ) def instruction_sub(self, ins: 'LoadedInstruction'): - INS_NOT_IMPLEMENTED(ins) + ASSERT_LEN(ins.args, 3) + dst = ins.get_reg(0) + src1 = ins.get_reg(1) + src2 = ins.get_reg(2) + self.regs.set( + dst, + self.regs.get(src1) - self.regs.get(src2) + ) def instruction_lui(self, ins: 'LoadedInstruction'): INS_NOT_IMPLEMENTED(ins) @@ -152,7 +159,14 @@ class CPU: INS_NOT_IMPLEMENTED(ins) def instruction_xor(self, ins: 'LoadedInstruction'): - INS_NOT_IMPLEMENTED(ins) + ASSERT_LEN(ins.args, 3) + dst = ins.get_reg(0) + src1 = ins.get_reg(1) + src2 = ins.get_reg(2) + self.regs.set( + dst, + self.regs.get(src1) ^ self.regs.get(src2) + ) def instruction_xori(self, ins: 'LoadedInstruction'): INS_NOT_IMPLEMENTED(ins) diff --git a/riscemu/helpers.py b/riscemu/helpers.py index 14226ec..b5be871 100644 --- a/riscemu/helpers.py +++ b/riscemu/helpers.py @@ -44,13 +44,14 @@ def int_from_bytes(bytes, unsigned=False): def to_unsigned(num: int, bytes=4): if num < 0: - return 2**(bytes * 8) - num + return 2**(bytes * 8) + num + return num def to_signed(num: int, bytes=4): if num >> (bytes * 8 - 1): return num - 2 ** (8 * bytes) - + return num # Colors