From 2a17186f74a54b84f653af88694db4c892e5578a Mon Sep 17 00:00:00 2001 From: doyle Date: Wed, 8 Mar 2023 08:24:20 +1100 Subject: [PATCH] perfaware/part1: Fix OOB 'w' bitshift for IMM->Reg, print signed output --- part1/sim8086.c | 8 ++++---- project.rdbg | Bin 914 -> 1002 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/part1/sim8086.c b/part1/sim8086.c index 0e764e4..31a918c 100644 --- a/part1/sim8086.c +++ b/part1/sim8086.c @@ -441,23 +441,23 @@ int main(int argc, char **argv) // NOTE: Parse opcode control bits // ============================================================= S86_ASSERT(stream.size == 1); - uint8_t w = (stream.bytes[0] & 0b0000'1000) >> 4; + uint8_t w = (stream.bytes[0] & 0b0000'1000) >> 3; uint8_t reg = (stream.bytes[0] & 0b0000'0111) >> 0; // NOTE: Parse data payload // ============================================================= stream.bytes[stream.size++] = S86_BufferIteratorNextByte(&buffer_it); - uint16_t data = stream.bytes[stream.size - 1]; + int16_t data = stream.bytes[stream.size - 1]; if (w) { // 16 bit data stream.bytes[stream.size++] = S86_BufferIteratorNextByte(&buffer_it); - data |= (uint16_t)(stream.bytes[stream.size - 1]) << 8; + data |= (int16_t)(stream.bytes[stream.size - 1]) << 8; } // NOTE: Disassemble // ============================================================= S86_Str8 dest_register = REGISTER_FIELD_ENCODING[w][reg]; - S86_PrintLnFmt("mov %.*s, %u", S86_STR8_FMT(dest_register), data); + S86_PrintLnFmt("mov %.*s, %d", S86_STR8_FMT(dest_register), data); } break; case S86_InstructionType_MOVMemToAccum: { diff --git a/project.rdbg b/project.rdbg index 4aa0a50d261d1c8fc466f5408261bf60781b5672..21eb7d33bbac1c06a4d8933761e38853fef5ae04 100644 GIT binary patch delta 81 zcmbQl{)&CVK3+x!2msOcllvJhxr;M%EetHo^pZIkCmz_#36fyr{&|FPavkFrR*+)$ W$qSj}!Qvn}#>pRMW@J`p^|9!c?|&DZ3-R$