aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/tests/testmemory.cpp
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-08-31 00:18:53 +0200
committerKarel Kočí <cynerd@email.cz>2017-08-31 00:18:53 +0200
commit82884b3ef726889f837542d2b5e98e2cd8246c00 (patch)
tree4f72237e5361256f2334b29d8b069388899c96ac /qtmips_machine/tests/testmemory.cpp
parentc975257cef23d254b1fa9290474268a61509e954 (diff)
downloadqtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.tar.gz
qtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.tar.bz2
qtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.zip
Handle endianness in memory correctly
Diffstat (limited to 'qtmips_machine/tests/testmemory.cpp')
-rw-r--r--qtmips_machine/tests/testmemory.cpp22
1 files changed, 22 insertions, 0 deletions
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);
+}