From 1abeab6f2df252b1d52ae12bcc856b92a5c22d90 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 19 Apr 2021 08:53:35 +0200 Subject: [PATCH] added parse_rs_rs_imm method to InstructionSet, used for branch instructions --- riscemu/instructions/InstructionSet.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/riscemu/instructions/InstructionSet.py b/riscemu/instructions/InstructionSet.py index 729e0bb..93d6c8d 100644 --- a/riscemu/instructions/InstructionSet.py +++ b/riscemu/instructions/InstructionSet.py @@ -78,6 +78,20 @@ class InstructionSet(ABC): to_unsigned(self.get_reg_content(ins, 1)), \ to_unsigned(ins.get_imm(2)) + def parse_rs_rs_imm(self, ins: 'LoadedInstruction', signed=True) -> Tuple[int, int, int]: + """ + Assumes the command is in rs1, rs2, imm format + Returns the values in rs1, rs2 and the immediate imm + """ + if signed: + return self.get_reg_content(ins, 0), \ + self.get_reg_content(ins, 1), \ + ins.get_imm(2) + else: + return to_unsigned(self.get_reg_content(ins, 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: """ get the register name from ins and then return the register contents