How to calculate a negative number in an assembly

I'm new to assembly, and I have a question about how to represent negative numbers. I have three DWORDS parameters, let's say:

result DWORD 0
i DWORD 3
j DWORD 5

and I want to calculate this formula: result = i - j + 8 but when I do ij, the result will be a very large number due to the sign so how can I make the result OK at the end?

+3
source share
2 answers

For a 32-bit DWORD, the integer range is -2147483648 to 2147483647 or in hex -0x80000000 to 0x7FFFFFFF.

Thus, the number -1 is present as 0xFFFFFFFF. (Like underflow counter)

If the high (31) bit is set, this number is negative. To make a positive number from a negative (negation), you must compliment the number and add 1.

Example:

    0xFFFFFFFE   //-2
xor 0xFFFFFFFF   //binary complement 
---------------
    0x00000001   //result of complement
+   0x00000001   //add 1
---------------
    0x00000002   //Result of negation is 2
+8

:

, , :

:

jg (jump if greater)
jl (jump if less)

( ):

ja (jump if greater)
jb (jump if less)
0

Source: https://habr.com/ru/post/1776538/


All Articles