def test_beq(): rd = "0" * 5 instruction = "0000000$rs2$rs1000100001100011" instruction = instruction.replace("$rs1", rd) instruction = instruction.replace("$rs2", rd) rs1 = 0b00000000000000000000000000001101 # 13 rs2 = 0b00000000000000000000000000001011 # 11 exp = 16 instr = ISA().instruction_from_bin(instruction, 0) assert exp == instr.execute(rs1, rs1) assert 4 == instr.execute(rs1, rs2)
def test_lui(): imm = "00000000000010101010" rd = "0" * 5 instruction = "$imm$rd0110111" instruction = instruction.replace("$imm", imm) instruction = instruction.replace("$rd", rd) exp = "10101010000000000000" instr = ISA().instruction_from_bin(instruction, 0) assert int(exp, 2) == instr.execute(None)
def test_auipc(): imm = "00000000000010101010" rd = "0" * 5 instruction = "$imm$rd0010111" instruction = instruction.replace("$imm", imm) instruction = instruction.replace("$rd", rd) exp_par = "10101010000000000000" PC = 24 exp = int(exp_par, 2) + PC instr = ISA().instruction_from_bin(instruction, 0) assert exp == instr.execute(PC)