From 82884b3ef726889f837542d2b5e98e2cd8246c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 31 Aug 2017 00:18:53 +0200 Subject: Handle endianness in memory correctly --- qtmips_machine/tests/testmemory.cpp | 22 ++++++++++++++++++++++ qtmips_machine/tests/tst_machine.h | 1 + 2 files changed, 23 insertions(+) (limited to 'qtmips_machine/tests') diff --git a/qtmips_machine/tests/testmemory.cpp b/qtmips_machine/tests/testmemory.cpp index 991e1f1..eac7dd6 100644 --- a/qtmips_machine/tests/testmemory.cpp +++ b/qtmips_machine/tests/testmemory.cpp @@ -59,3 +59,25 @@ void MachineTests::memory_section() { // Read trough memory QCOMPARE(m.read_byte(address), (std::uint8_t)0x66); } + +void MachineTests::memory_endian() { + Memory m; + + // Memory should be bit endian so write bytes from most significant byte + m.write_byte(0x00, 0x12); + m.write_byte(0x01, 0x34); + m.write_byte(0x02, 0x56); + m.write_byte(0x03, 0x78); + QCOMPARE(m.read_hword(0x00), (std::uint16_t)0x1234); + QCOMPARE(m.read_word(0x00), (std::uint32_t)0x12345678); + + m.write_hword(0x80, 0x1234); + QCOMPARE(m.read_byte(0x80), (std::uint8_t)0x12); + QCOMPARE(m.read_byte(0x81), (std::uint8_t)0x34); + + m.write_word(0xF0, 0x12345678); + QCOMPARE(m.read_byte(0xF0), (std::uint8_t)0x12); + QCOMPARE(m.read_byte(0xF1), (std::uint8_t)0x34); + QCOMPARE(m.read_byte(0xF2), (std::uint8_t)0x56); + QCOMPARE(m.read_byte(0xF3), (std::uint8_t)0x78); +} diff --git a/qtmips_machine/tests/tst_machine.h b/qtmips_machine/tests/tst_machine.h index 214ab88..e5137c4 100644 --- a/qtmips_machine/tests/tst_machine.h +++ b/qtmips_machine/tests/tst_machine.h @@ -16,6 +16,7 @@ private Q_SLOTS: void memory_data(); void memory_section(); void memory_section_data(); + void memory_endian(); }; #endif // TST_MACHINE_H -- cgit v1.2.3