From 15e8473e7e9722d807ae6c49b8d3275db9969028 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Fri, 6 Apr 2012 22:49:33 -0700 Subject: [PATCH] emulator: Correct bugs in dcpu_skip(). PC increment must be preincrement in order to look up the correct instruction. Additionally, skiptable lookups must be masked or else garbage will be read, which can cause skips of more than one per operand. Fixes several bugs in my Forth compiler's output when generating IFE instructions. --- emulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emulator.c b/emulator.c index 7544c8d..12b82a7 100644 --- a/emulator.c +++ b/emulator.c @@ -98,8 +98,8 @@ static u8 skiptable[32] = { /* operand forms that advance pc */ }; void dcpu_skip(struct dcpu *d) { - u16 op = d->m[d->pc++]; - d->pc += skiptable[op >> 10]; + u16 op = d->m[++d->pc]; + d->pc += skiptable[(op >> 10) & 31]; if ((op & 15) == 0) d->pc += skiptable[(op >> 4) & 31]; }