diff options
| author | Guillaume Valadon <guillaume@valadon.net> | 2018-06-15 12:10:10 +0200 |
|---|---|---|
| committer | Guillaume Valadon <guillaume@valadon.net> | 2018-07-12 22:50:51 +0200 |
| commit | b8e5038798b0dece628846acb5ad25d9d4e60395 (patch) | |
| tree | 932dd2676afcf0c4ba6bf0c57d3b574954461ad2 /test/arch/mep/asm/test_asm.py | |
| parent | 82eb5f6eb197fc59d2e9ae21cfda05a1868e462e (diff) | |
| download | miasm-b8e5038798b0dece628846acb5ad25d9d4e60395.tar.gz miasm-b8e5038798b0dece628846acb5ad25d9d4e60395.zip | |
Toshiba MeP support
Diffstat (limited to 'test/arch/mep/asm/test_asm.py')
| -rw-r--r-- | test/arch/mep/asm/test_asm.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/arch/mep/asm/test_asm.py b/test/arch/mep/asm/test_asm.py new file mode 100644 index 00000000..ddf91ed6 --- /dev/null +++ b/test/arch/mep/asm/test_asm.py @@ -0,0 +1,38 @@ +# Toshiba MeP-c4 - Misc unit tests +# Guillaume Valadon <guillaume@valadon.net> + +from miasm2.arch.mep.arch import mn_mep + +class TestMisc: + + def test(self): + + # Disassemble & assemble unit tests + unit_tests = [("ADD R1, 2", "6108")] + unit_tests += [("JMP 0xC3FA38", "d9c8c3fa")] + unit_tests += [("SLT3 R0, R8, R10", "08a2")] + unit_tests += [("SB R9, (R4)", "0948")] + unit_tests += [("SSARB 3(GP)", "13ec")] + unit_tests += [("SWCPI C13, (R2+)", "3d20")] + unit_tests += [("ADD3 R2, SP, 0x1C", "421c")] + unit_tests += [("SW R7, 0x50(SP)", "4752")] + + for mn_str, mn_hex in unit_tests: + print "-" * 49 # Tests separation + + # Dissassemble + mn_bin = mn_hex.decode("hex") + mn = mn_mep.dis(mn_bin, "b") + + print "dis: %s -> %s" % (mn_hex.rjust(20), str(mn).rjust(20)) + assert(str(mn) == mn_str) # dissassemble assertion + + # Assemble and return all possible candidates + instr = mn_mep.fromstring(str(mn), "b") + instr.mode = "b" + asm_list = [i.encode("hex") for i in mn_mep.asm(instr)] + + # Print the results + print "asm: %s -> %s" % (mn_str.rjust(20), + ", ".join(asm_list).rjust(20)) + assert(mn_hex in asm_list) # assemble assertion |