Conversation
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.
|
In hex: Disassembled: |
|
Ugh, sorry, GH apparently eats formatting and comments in this browser. Anyway, the point is that at 0x000e, the IFE should only go to 0x000f or 0x0010, but instead it goes off to lala-land without my patch. I thought about the pre/post-increment, and I agreed with you at first, but then I stepped through with GDB and realized that it needs to be pre-increment in order to examine the correct word. |
|
There are two changes here:
|
|
Well, TBH I no longer use this emulator because Cauliflower and goforth are both at the advanced stage where they require I/O to be implemented to be emulated correctly. Anyway, if you look at the code I posted, and read through it, and agree that it should behave in a certain way, then this patch does make it behave in that way. I should point out that this patch was before the massive sequence of refactors which recently happened, so it's totally possible that PC is in a more consistent state coming into |
|
Re: the mask value: 0x1f (31): this is needed to avoid overflowing skiptable, just as you said. I was wrong when I said the unsigned shift would take care of things. But, masking with 0x1F leads to its own problems: now literal values (operand codes 0x20 - 0x3F) alias down to indices 0x0 - 0x1F in skiptable; some of those literal values are then incorrectly identified as values which imply an additional instruction word. I've got another fix which avoids this problem as well, and a testcase to show failure before the fix, correct function after. I've just pull-requested it, have a look if you like, comments welcome. |
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.