summaryrefslogtreecommitdiffhomepage
path: root/test-asm.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-10-17 17:37:50 +0200
committerRoland Reichwein <mail@reichwein.it>2020-10-17 17:37:50 +0200
commit7b49d17f90f26394a116348befb5edcdffcedcb6 (patch)
treec32e76a9bea5851bfac92708fa626373573e4f06 /test-asm.cpp
parentf86999e137f43372236f2dccd1fe3572a85c0dcd (diff)
Add ret and int
Diffstat (limited to 'test-asm.cpp')
-rw-r--r--test-asm.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/test-asm.cpp b/test-asm.cpp
new file mode 100644
index 0000000..882f998
--- /dev/null
+++ b/test-asm.cpp
@@ -0,0 +1,92 @@
+#include "asm/chunk.h"
+#include "asm/assembler.h"
+#include "asm/segment.h"
+#include "asm/intel64/all_ops.h"
+
+#include "minicc.h"
+
+#include <boost/algorithm/string.hpp>
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include <algorithm>
+#include <cctype>
+#include <deque>
+#include <map>
+#include <memory>
+#include <string>
+#include <system_error>
+#include <utility>
+#include <vector>
+
+using namespace std::string_literals;
+namespace fs = std::filesystem;
+
+class AsmTest: public ::testing::Test
+{
+protected:
+ AsmTest() {
+ //debug = true;
+ }
+ ~AsmTest() {
+ }
+ void SetUp(){
+ }
+ void TearDown(){
+ }
+};
+
+TEST_F(AsmTest, Intel64_int_0) {
+ Segment segment;
+ AsmArgs args{{Immediate8(0)}};
+ segment.push_back(makeOp("int", args));
+
+ ASSERT_EQ(segment.size(), 1);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>{0xCE});
+}
+
+TEST_F(AsmTest, Intel64_int_1) {
+ Segment segment;
+ AsmArgs args{{Immediate8(1)}};
+ segment.push_back(makeOp("int", args));
+
+ ASSERT_EQ(segment.size(), 1);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>{0xF1});
+}
+
+TEST_F(AsmTest, Intel64_int_5) {
+ Segment segment;
+ AsmArgs args{{Immediate8(5)}};
+ segment.push_back(makeOp("int", args));
+
+ ASSERT_EQ(segment.size(), 1);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>({0xCD, 0x05}));
+}
+
+TEST_F(AsmTest, Intel64_nop) {
+ Segment segment;
+ segment.push_back(makeOp("nop"));
+
+ ASSERT_EQ(segment.size(), 1);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>{0x90});
+}
+
+TEST_F(AsmTest, Intel64_ret) {
+ Segment segment;
+ segment.push_back(makeOp("ret"));
+
+ ASSERT_EQ(segment.size(), 1);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>{0xC3});
+}
+
+TEST_F(AsmTest, Intel64_multiple) {
+ Segment segment;
+ segment.push_back(makeOp("nop"));
+ AsmArgs args{{Immediate8(5)}};
+ segment.push_back(makeOp("int", args));
+ segment.push_back(makeOp("ret"));
+
+ ASSERT_EQ(segment.size(), 3);
+ ASSERT_EQ(segment.getCode(), std::vector<uint8_t>({0x90, 0xCD, 0x05, 0xC3}));
+}