Assembly x86 registers signed or unsigned

user3604597 picture user3604597 · Dec 28, 2014 · Viewed 9.9k times · Source

I know this is a really simple question, but I couldn't find an answer to this. Are the registers in x86 assembly (eax, ebx edx etc) signed or unsigned? If they're signed by default, how does the computer know to treat the registers as unsigned if for example we will declare a variable as unsigned int? Thanks!

Answer

Jongware picture Jongware · Dec 28, 2014

The CPU does not know nor does it care. Instead, bits in the Flags register are set on certain operations, and how your program acts on those flags depends on what the source code told it to.

E.g.,

mov eax, 0FFFFFFFFh
test eax, eax
js isNegative

vs.

mov eax, 0FFFFFFFFh
test eax, eax
jb isNegative

The first jumps to 'IsNegative' because test sets the Sign Flag here. The second does not, because test resets the Carry Flag to 0 and jb only jumps if it is 1.