I have a simple C code:
int main(){
int a = -1;
long b = 4294967295;
return 0;
}
Compiling it with no optimization and looking at it's assembly using GDB shows the following:
0x0000000100000f90 <+0>: push %rbp
0x0000000100000f91 <+1>: mov %rsp,%rbp
0x0000000100000f94 <+4>: xor %eax,%eax
0x0000000100000f96 <+6>: mov $0xffffffff,%ecx
0x0000000100000f9b <+11>: mov %ecx,%edx
0x0000000100000f9d <+13>: movl $0x0,-0x4(%rbp)
0x0000000100000fa4 <+20>: movl $0xffffffff,-0x8(%rbp)
0x0000000100000fab <+27>: mov %rdx,-0x10(%rbp)
0x0000000100000faf <+31>: pop %rbp
0x0000000100000fb0 <+32>: retq
As you can see both a and b are represented with 0xffffffff. Here are my questions:
1) Why is the first occurrence of 0xffffffff stored in ecx before being moved on the stack, why mov is used instead of movl. Does it make any difference in the 2's complement world?
2) Looking at a raw register value, how can you tell if it's a positive or a negative number (in 2's complement)?
2) Does the CPU know/care if this number is in 2's complement mode or it only cares about the op code it uses for the calculation?
User contributions licensed under CC BY-SA 3.0