big endian

This commit is contained in:
sfja 2026-02-15 22:00:56 +01:00
parent b7ed64e6c0
commit 6a3e022d90
2 changed files with 6 additions and 6 deletions

View File

@ -79,8 +79,8 @@ public:
void push(uint16_t v) void push(uint16_t v)
{ {
m_data[m_ip] = v & 0xff; m_data[m_ip] = v >> 8;
m_data[m_ip + 1] = v >> 8; m_data[m_ip + 1] = v & 0xff;
m_ip += 2; m_ip += 2;
} }

View File

@ -145,8 +145,8 @@ uint16_t VM::word(uint16_t addr) const
} }
uint16_t value = 0; uint16_t value = 0;
value |= m_mem[addr]; value |= static_cast<uint16_t>(m_mem[addr]) << 8;
value |= static_cast<uint16_t>(m_mem[addr + 1]) << 8; value |= m_mem[addr + 1];
return value; return value;
} }
@ -167,8 +167,8 @@ void VM::set_word(uint16_t addr, uint16_t value)
std::format("invalid address alignment, addr = {}", addr)); std::format("invalid address alignment, addr = {}", addr));
} }
m_mem[addr] = value & 0xff; m_mem[addr] = value >> 8;
m_mem[addr + 1] = value >> 8; m_mem[addr + 1] = value & 0xff;
} }
void VM::set_byte(uint16_t addr, uint8_t value) void VM::set_byte(uint16_t addr, uint8_t value)