summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-asm.cpp35
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);