diff options
author | Karel Kočí <cynerd@email.cz> | 2017-08-31 00:18:53 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-08-31 00:18:53 +0200 |
commit | 82884b3ef726889f837542d2b5e98e2cd8246c00 (patch) | |
tree | 4f72237e5361256f2334b29d8b069388899c96ac /qtmips_machine/tests | |
parent | c975257cef23d254b1fa9290474268a61509e954 (diff) | |
download | qtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.tar.gz qtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.tar.bz2 qtmips-82884b3ef726889f837542d2b5e98e2cd8246c00.zip |
Handle endianness in memory correctly
Diffstat (limited to 'qtmips_machine/tests')
-rw-r--r-- | qtmips_machine/tests/testmemory.cpp | 22 | ||||
-rw-r--r-- | qtmips_machine/tests/tst_machine.h | 1 |
2 files changed, 23 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); +} 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 |