Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in dcpu_skip, add a test program. #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

aaronferrucci
Copy link

I've found and fixed a big in dcpu_skip, have a look and see if you think it's worth merging with your main branch. I've included a test which fails with the bug, and passes with my fix.

Aaron Ferrucci added 5 commits April 17, 2012 22:33
misses the pc increment for the b operand in a basic instruction.

The test shows that a 3-word instruction is not properly skipped.  The 3rd word
of the instruction (SET [0x1000], [0xEEE0]), when mistakenly interpreted
as the 1st word of the next instruction, causes an illegal opcode bailout
in the monitor.
…l non-basic

opcodes to use as an emulator success code.
… for

non-basic opcodes) could overflow skiptable, when used as an index. Masking
the operand to force it within the table size has its own problem, as it
causes aliasing from some constant operands to operands which "advance pc".

Example:

c00d	009c:	IFN A, 16
fc03	009d:	SUB A, 31

The constant 31 in the second instruction is 'b' operand value 0x3F.  If
masked with 31 (0x1F) to stay within the table, it becomes 0x1F, which has
value 1 within skiptable - that's incorrect, the constant does not require
another instruction word.

The solution in this commit tries to perturb the existing code as little
as possible; I just bump skiptable up to 64-locations, so there's no
need to mask the operand before using it as an index.  The other change
is to update the mask on the basic-opcode 'a' operand so that literals
are handled correcty for that operand as well.

I've included a test case, "testskip3.s", which fails before the fix and
passes after the fix.  All 32 literal operand values for the 'b' operand
are tested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant