I'm building an x86 emulator, and I'm using this online x86 sandbox to check my work. In my emulator, running this code:
mov AX, 0xFFFF
add AX, AX
...sets AX to 0xFFFE and sets the overflow flag to 0.
In the sandbox, the same code sets the overflow flag to 1. This doesn't make sense to me, because every definition of the OF I've read explains that it gets set if 1) the source and destination operands have the same sign, and 2) the sign of the result != the sign of the source/destination operands.
Here, we're adding 0b1111 1111 1111 1111 to 0b1111 1111 1111 1111. The result is 0b1111 1111 1111 1110. The sign bit of the source, destination, and result are all 1. Whether we interpret this as 0xFFFF + 0xFFFF = 0xFFFE (implicitly 0x1FFFE), or as -1 + -1 = -2, the sign is not changing.
Is this sandbox implementation wrong? If not, can you help me understand what I'm missing?
You're right. Sandbox wrong.
I expected this before trying it because logically (-1 + -1 = -2) and no signed overflow occurred. V is signed overflow.