Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly x86 registers signed or unsigned

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!

like image 955
user3604597 Avatar asked Dec 28 '14 15:12

user3604597


People also ask

Are registers signed or unsigned?

32-bit registers in x86 are default unsigned. For example, a move from 32-bit operand to a 64-bit register always get zero-extended under long model. But instructions each has its own interpretation of registers based on its purpose, like 'add' instruction take registers both signed or unsigned.

Do registers hold unsigned integers?

Signed and unsigned integers can be stored in the registers. The unsigned numbers are read from or written to the Modbus device using simple addressing, like H or R to holding and input registers.

Is x86 register register?

The x86 architecture contains eight 32-bit General Purpose Registers (GPRs). These registers are mainly used to perform address calculations, arithmetic and logical calculations. Four of the GPRs can be treated as a 32-bit quantity, a 16-bit quantity or as two 8-bit quantities.

What is signed and unsigned integer in assembly language?

Signed variables, such as signed integers will allow you to represent numbers both in the positive and negative ranges. Unsigned variables, such as unsigned integers, will only allow you to represent numbers in the positive.


2 Answers

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.

like image 195
Jongware Avatar answered Sep 20 '22 07:09

Jongware


32-bit registers in x86 are default unsigned. For example, a move from 32-bit operand to a 64-bit register always get zero-extended under long model. But instructions each has its own interpretation of registers based on its purpose, like 'add' instruction take registers both signed or unsigned. You should refer intel documents for detail.

like image 25
Jacky Tsao Avatar answered Sep 19 '22 07:09

Jacky Tsao