From 739297d8895b08a9ecd8e81b01b7ba8e8dc4a8ae Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 21 Nov 2020 22:57:25 +0100 Subject: Bugfix push + pop --- tests/test-asm.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/test-asm.cpp') diff --git a/tests/test-asm.cpp b/tests/test-asm.cpp index 650a48a..6c03f48 100644 --- a/tests/test-asm.cpp +++ b/tests/test-asm.cpp @@ -146,6 +146,41 @@ TEST_F(AsmTest, Intel64_multiple) { })); } +TEST_F(AsmTest, indexed_to) { + Segment segment; + + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Mem32Ptr64("rbp", -4), Asm::Args::Immediate32(3)}})); + + ASSERT_EQ(segment.size(), size_t(1)); + ASSERT_EQ(segment.getCode(), std::vector({0xC7, 0x45, 0xFC, 0x03, 0x00, 0x00, 0x00})); +} + +TEST_F(AsmTest, indexed_from) { + Segment segment; + + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Mem32Ptr64("rbp", -4)}})); + + ASSERT_EQ(segment.size(), size_t(1)); + ASSERT_EQ(segment.getCode(), std::vector({0x8B, 0x7D, 0xFC})); +} + +TEST_F(AsmTest, frame_pointer) { + Segment segment; + + segment.push_back(makeOp("push", Asm::Args{{Asm::Args::Register64("rbp")}})); + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rsp")}})); + + // frame at [rbp-...] available here ... + + segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); + + ASSERT_EQ(segment.size(), size_t(3)); + ASSERT_EQ(segment.getCode(), std::vector({ + 0x55, + 0x48, 0x89, 0xE5, + 0x5D})); +} + TEST_F(AsmParseTest, parse_empty) { std::vector> chunks0{parseAsm("")}; ASSERT_EQ(chunks0.size(), 0u); -- cgit v1.2.3