I working with 8086 emulator There is a instruction mov dx,-16 After executing this instruction, I got result like below enter image description here
Can anyone please tell me how this value comes?
I working with 8086 emulator There is a instruction mov dx,-16 After executing this instruction, I got result like below enter image description here
Can anyone please tell me how this value comes?
The highest bit is used as a sign flag. If it's set to 0, the rest is just a normal value without the highest bit. If it's 1, then you have to take 2 to the power of the amont of bits - 1 for the sign flag (in that case 15) and then add the normal value. Or you just take 0x10000 and subtract the absolute value.
The great thing about this is that, for example, when you only have 8 bit registers (I'm a C64 guy) you can add 0xFF (which means -1) to, let's say, 0x05, and you get 0x104. But since there is no 9th bit, it's only 0x04. So CPUs have some kind of "native support" for that kind of signed numbers since you can pretty much treat them like normal numbers.
For your case it means that you take 0x10000 and then subtract 16 so you get 0xFFF0.
A negative number is indicated by the highest bit set. If you subtract 1 from 0 then you get 0xffff = -1 because the register wraps around.
0xffff = -1
0xfffe = -2
...
0xfff0 = -16
But this is a convention, how you interpret the number (or use it in certain operations), because if you treat the same value as unsigned, then you have the range 0...65535 | 0...0xffff.
So basically, because the highest bit indicates a negative value, this means that the range of the values are halfed to -32768 ... +32767.