From d40c80cb8154b9159bc2d5fb29862742e8e661f7 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 19 Apr 2021 08:37:16 +0200 Subject: [PATCH] added unsigned options to instruction parsing --- riscemu/instructions/InstructionSet.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/riscemu/instructions/InstructionSet.py b/riscemu/instructions/InstructionSet.py index 5f7e6ea..729e0bb 100644 --- a/riscemu/instructions/InstructionSet.py +++ b/riscemu/instructions/InstructionSet.py @@ -48,21 +48,35 @@ class InstructionSet(ABC): rd = ins.get_reg(0) return rd, rs + imm - def parse_rd_rs_rs(self, ins: 'LoadedInstruction') -> Tuple[str, int, int]: + def parse_rd_rs_rs(self, ins: 'LoadedInstruction', signed=True) -> Tuple[str, int, int]: """ Assumes the command is in rd, rs1, rs2 format Returns the name of rd, and the values in rs1 and rs2 """ ASSERT_LEN(ins.args, 3) - return ins.get_reg(0), self.get_reg_content(ins, 1), self.get_reg_content(ins, 2) + if signed: + return ins.get_reg(0), \ + self.get_reg_content(ins, 1), \ + self.get_reg_content(ins, 2) + else: + return ins.get_reg(0), \ + to_unsigned(self.get_reg_content(ins, 1)), \ + to_unsigned(self.get_reg_content(ins, 2)) - def parse_rd_rs_imm(self, ins: 'LoadedInstruction') -> Tuple[str, int, int]: + def parse_rd_rs_imm(self, ins: 'LoadedInstruction', signed=True) -> Tuple[str, int, int]: """ Assumes the command is in rd, rs, imm format Returns the name of rd, the value in rs and the immediate imm """ ASSERT_LEN(ins.args, 3) - return ins.get_reg(0), self.get_reg_content(ins, 1), ins.get_imm(2) + if signed: + return ins.get_reg(0), \ + self.get_reg_content(ins, 1), \ + ins.get_imm(2) + else: + return ins.get_reg(0), \ + to_unsigned(self.get_reg_content(ins, 1)), \ + to_unsigned(ins.get_imm(2)) def get_reg_content(self, ins: 'LoadedInstruction', ind: int) -> int: """