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

SBX underflow sets EX to 0x0001 instead of 0xffff #65

Open
Olathe opened this issue Aug 8, 2012 · 0 comments
Open

SBX underflow sets EX to 0x0001 instead of 0xffff #65

Olathe opened this issue Aug 8, 2012 · 0 comments

Comments

@Olathe
Copy link

Olathe commented Aug 8, 2012

It's not really that easy to do 64-bit subtraction because SBX is screwed up.

The 1.7 spec says:
3 | 0x1b | SBX b, a | sets b to b-a+EX, sets EX to 0xFFFF if there is an underflow, 0x0 otherwise

Here's some test code:

SET A, 0x0123
SET B, 0x4567
SET C, 0x89ab
SET X, 0xcdef

SET Y, 0x0123
SET Z, 0x4567
SET I, 0x89ab
SET J, 0xcdf0

; Find ABCX - YZIJ (should be 0xffffffffffffffff, or -1, since YZIJ = ABCX + 1)
SUB X, J
SBX C, I
SBX B, Z
SBX A, Y

This is similar to the 64-bit addition code, which uses ADD and ADXlike that. Unfortunately, because SBX works improperly (it sets EX to 1 after the second underflow, so it adds 1 rather than borrowing 1) we get incorrect results.

This was discussed here: http://0x10cforum.com/forum/page/1/m/4932880/viewthread/2964261-which-result-correct-for-sbx

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

No branches or pull requests

1 participant