def test_invalid_field_shamt(): with pytest.raises(AssertionError): pisa_encoding.assemble_inst({}, 0, "sll r1, r2, 32") with pytest.raises(AssertionError): pisa_encoding.assemble_inst({}, 0, "sll r1, r2, -1")
def test_invalid_field_rd(): with pytest.raises( AssertionError ): pisa_encoding.assemble_inst( {}, 0, "addu r1, r2, 3" ) with pytest.raises( AssertionError ): pisa_encoding.assemble_inst( {}, 0, "addu r1, r2, r32" )
def test_invalid_field_rd(): with pytest.raises(AssertionError): pisa_encoding.assemble_inst({}, 0, "addu r1, r2, 3") with pytest.raises(AssertionError): pisa_encoding.assemble_inst({}, 0, "addu r1, r2, r32")
def test_invalid_field_shamt(): with pytest.raises( AssertionError ): pisa_encoding.assemble_inst( {}, 0, "sll r1, r2, 32" ) with pytest.raises( AssertionError ): pisa_encoding.assemble_inst( {}, 0, "sll r1, r2, -1" )
def check( inst_str, inst_bits_ref, inst_str_ref ): inst_bits = pisa_encoding.assemble_inst( {}, 0, inst_str ) assert inst_bits == inst_bits_ref inst_str = pisa_encoding.disassemble_inst( inst_bits ) assert inst_str == inst_str_ref
def check_sym( sym, pc, inst_str, inst_bits_ref, inst_str_ref ): inst_bits = pisa_encoding.assemble_inst( sym, pc, inst_str ) assert inst_bits == inst_bits_ref inst_str = pisa_encoding.disassemble_inst( inst_bits ) assert inst_str == inst_str_ref
def check(inst_str, inst_bits_ref, inst_str_ref): inst_bits = pisa_encoding.assemble_inst({}, 0, inst_str) assert inst_bits == inst_bits_ref inst_str = pisa_encoding.disassemble_inst(inst_bits) assert inst_str == inst_str_ref
def test_fields_shamt(): inst = PisaInst( assemble_inst( {}, 0, "sll r15, r16, 31" ) ) assert inst.name == "sll" assert inst.rd == 15 assert inst.rt == 16 assert inst.shamt == 31
def test_fields_reg(): inst = PisaInst( assemble_inst( {}, 0, "addu r1, r2, r3" ) ) assert inst.name == "addu" assert inst.rd == 1 assert inst.rs == 2 assert inst.rt == 3
def test_fields_imm(): inst = PisaInst( assemble_inst( {}, 0, "addiu r30, r31, 0x4eef" ) ) assert inst.name == "addiu" assert inst.rt == 30 assert inst.rs == 31 assert inst.imm == 0x4eef
def test_fields_shamt(): inst = PisaInst(assemble_inst({}, 0, "sll r15, r16, 31")) assert inst.name == "sll" assert inst.rd == 15 assert inst.rt == 16 assert inst.shamt == 31
def test_fields_imm(): inst = PisaInst(assemble_inst({}, 0, "addiu r30, r31, 0x4eef")) assert inst.name == "addiu" assert inst.rt == 30 assert inst.rs == 31 assert inst.imm == 0x4eef
def test_fields_reg(): inst = PisaInst(assemble_inst({}, 0, "addu r1, r2, r3")) assert inst.name == "addu" assert inst.rd == 1 assert inst.rs == 2 assert inst.rt == 3
def check_sym(sym, pc, inst_str, inst_bits_ref, inst_str_ref): inst_bits = pisa_encoding.assemble_inst(sym, pc, inst_str) assert inst_bits == inst_bits_ref inst_str = pisa_encoding.disassemble_inst(inst_bits) assert inst_str == inst_str_ref
def test_fields_jtarg(): inst_bits = assemble_inst( {"label":0x1010}, 0x1000, "j label" ) inst = PisaInst( inst_bits ) assert inst.name == "j" assert inst.jtarg == 0x00404
def test_fields_jtarg(): inst_bits = assemble_inst({"label": 0x1010}, 0x1000, "j label") inst = PisaInst(inst_bits) assert inst.name == "j" assert inst.jtarg == 0x00404
def test_invalid_field_imm_sext(): with pytest.raises( AssertionError ): pisa_encoding.assemble_inst( {}, 0, "addiu r1, r2, -0xffff" )
def test_invalid_field_imm_sext(): with pytest.raises(AssertionError): pisa_encoding.assemble_inst({}, 0, "addiu r1, r2, -0xffff")