Hi,
PearOs wrote:lock mov al,[si-0x1000] and 0x1000 is (61440) so thats good but why is it minus now? Cause if I write that
instruction in Nasm and decompile it, it will say that "+ 61440" is "- 61440" when thats not what I typed. But if I do "- 61440" I get "+ 61440" from Nasm Dism, did I just find a bug?
Note that -4096 (as a signed 16-bit number) is the exact same pattern of bits as 61440 (as an unsigned 16-bit number).
I'm not sure if this is a bug or correct behaviour.
If you assume that the displacement is a signed 16-bit value, then it'd only be capable of storing values from -32768 to +32767 and "[si+61440]" should be treated as a programming error (number too large for signed 16-bit).
If you assume that the displacement is an unsigned 16-bit value (where the CPU ignores overflow and essentially does "offset = (si + unsigned_displacement) & 0xFFFF") then it's not a bug at all.
If you assume that either case is equally valid (e.g. the programmer is free to treat the displacement as signed or unsigned), then that means valid values for the displacement would range from -32768 to 65535.
I tested NASM, and it does accept any value from -32768 to 65536 (inclusive), and gives a "data exceeds bounds" warning for anything outside that range. I don't know why 65536 is allowed (it doesn't fit in any signed or unsigned 16-bit integer).
For debuggers, it's impossible to guess what the original programmer's intent was, and a debugger can't know if it should display "-0x1000" or "+0xF000". Any debugger that displays "-0xF000" is buggy, but I tested ndisasm and it doesn't do that (it displays "-0x1000").
Cheers,
Brendan