added instruction xor

float_support
Anton Lydike 4 years ago
parent 99de083894
commit f8e595b46e

@ -143,7 +143,14 @@ class CPU:
) )
def instruction_sub(self, ins: 'LoadedInstruction'): 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'): def instruction_lui(self, ins: 'LoadedInstruction'):
INS_NOT_IMPLEMENTED(ins) INS_NOT_IMPLEMENTED(ins)
@ -152,7 +159,14 @@ class CPU:
INS_NOT_IMPLEMENTED(ins) INS_NOT_IMPLEMENTED(ins)
def instruction_xor(self, ins: 'LoadedInstruction'): 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'): def instruction_xori(self, ins: 'LoadedInstruction'):
INS_NOT_IMPLEMENTED(ins) INS_NOT_IMPLEMENTED(ins)

@ -44,13 +44,14 @@ def int_from_bytes(bytes, unsigned=False):
def to_unsigned(num: int, bytes=4): def to_unsigned(num: int, bytes=4):
if num < 0: if num < 0:
return 2**(bytes * 8) - num return 2**(bytes * 8) + num
return num
def to_signed(num: int, bytes=4): def to_signed(num: int, bytes=4):
if num >> (bytes * 8 - 1): if num >> (bytes * 8 - 1):
return num - 2 ** (8 * bytes) return num - 2 ** (8 * bytes)
return num
# Colors # Colors

Loading…
Cancel
Save