: Can I use a negative num as operand? : for exmple: : add eax, -1 : or : sub eax, -1
Yes.
: Can I use dec, when the register's value is 0? : for exmple: : mov eax,0 : dec eax
Yes. The result will simply be -1 if you think in terms of signed numbers. As an unsigned number it will be the largest number that can be represented in the register. For eax this is 0FFFFFFFFh (4,294,967,295). Additions and subtractions always wrap around the largest number available. This means that, for example, if you were to add 1 to 0FFFFFFFFh, then the result would be 0, because the 32-bit eax register has no more bits left to hold any larger numbers.
This applies to the above example too: add eax, -1 [color=Grey]is really the same as[/color] add eax, 0ffffffffh [color=Grey]and equivalent to[/color] sub eax, 1
Comments
: for exmple:
: add eax, -1
: or
: sub eax, -1
Yes.
: Can I use dec, when the register's value is 0?
: for exmple:
: mov eax,0
: dec eax
Yes. The result will simply be -1 if you think in terms of signed numbers. As an unsigned number it will be the largest number that can be represented in the register. For eax this is 0FFFFFFFFh (4,294,967,295). Additions and subtractions always wrap around the largest number available. This means that, for example, if you were to add 1 to 0FFFFFFFFh, then the result would be 0, because the 32-bit eax register has no more bits left to hold any larger numbers.
This applies to the above example too:
add eax, -1
[color=Grey]is really the same as[/color]
add eax, 0ffffffffh
[color=Grey]and equivalent to[/color]
sub eax, 1
To understand this better, it's really useful to know the basic theory behind binary data representation, here's a good start:
[link=http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_1/CH01-1.html]http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_1/CH01-1.html[/link]
[link=http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_1/CH01-2.html]http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_1/CH01-2.html[/link]