IMUL instead of MULIDIV instead of DIV
I'm not sure how you do the addition/subtraction, but I've never usedsigned variables via assembly myself...URL:http://acheronx.ml.org/home/
OK... Pretend we're working with a signed word.
A number (signed) is negative if it is between32768 and 65535. 65535 is -1. This is handybecause 0 - 1 = 65535 because of underflow!!!32768 is -32768! Experiment to see how it isthat way. It just simplifies things becausewith addition and subtraction, you don't needto worry about the sign - 3 + (-6) = 65533 = -3!!
It is true for multiplication/division that youneed to use IDIV and IMUL. Experiment to seefor yourself!!! (9 / -3 = -3; 3 / 65533 = ??)*it might work to do MUL /w signed nums IN SOMECASES!*
Get it??? Mail me if you need more help...
: IMUL instead of MUL: IDIV instead of DIV
: I'm not sure how you do the addition/subtraction, but I've never used: signed variables via assembly myself...
You are correct, the assembler and even the processor do not knowor even care whether you are working with signed or unsigned numbers.It is all your job to remember, and use the special IMUL and IDIVinstructions.
As to addition and subtraction...
The x86 stores negative numbers in what's called "twos complement."To get the negative of a number, you do a "ones complement", changingevery 0 bit to 1 and 1 to 0, and then you add 1.
Thus 1 (0000000000000001) turns into -1 (1111111111111111) .
And you could work out the rest for yourself.
They do this because with signed numbers kept this way, addition andsubtraction do not have to be recoded, they work just the same as always.See for yourself:
1 (0000000000000001) + -1 (1111111111111111)_____ 0 (0000000000000000) with a carried 1
You ignore the carry and voila: 1 + (-1) = 0.
Same for all the other negative numbers.
Twos complement also has the use of following the "one in the high bitfor negative" behavior. So that you can quickly determine if a numberis positive or negative by examining the high bit.
As you may see, multiplication and division to not work the same, sowe have special instructions for them.
Am I helping?
It looks like you're new here. If you want to get involved, click one of these buttons!