diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-21 22:57:25 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-21 22:57:25 +0100 |
commit | 739297d8895b08a9ecd8e81b01b7ba8e8dc4a8ae (patch) | |
tree | de0c20a23a60c1ccca8585f5ddd71eeb6be25623 /tests | |
parent | 39bccce4fdd1d5ebe312321c963e0325e4d696c5 (diff) |
Bugfix push + pop
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-asm.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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<uint8_t>({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<uint8_t>({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<uint8_t>({ + 0x55, + 0x48, 0x89, 0xE5, + 0x5D})); +} + TEST_F(AsmParseTest, parse_empty) { std::vector<std::shared_ptr<Chunk>> chunks0{parseAsm("")}; ASSERT_EQ(chunks0.size(), 0u); |