I read here, that there are different arithmetical assembly instructions for signed operations. However consider code:
unsigned char a = 0xff;
if(a == 0xff){
// do something
}
I remember in collage I made such code and the if
condition was never true, but it was on AVR. I have seen similar thing in my work, so I typed that to the godbolt and for x86 it shows:
mov BYTE PTR [rbp-1], -1
cmp BYTE PTR [rbp-1], -1
jne .L2
which is disturbing, because it shows, that unsigned modifier is ignored. Is it regulated by standard and gcc just simplified for optimalization purposes and actually converted 0xff
to unsigned?
EDIT: There was some confusion about my original problem (that's on me I didn't mention my example was meant for 8bit processor) so here's an alternative:
int main(){
unsigned int a = 0xffffffff;
if(a == -1)
return 0;
return 1;
}
translates to:
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], -1
cmp DWORD PTR [rbp-4], -1
jne .L2
mov eax, 0
jmp .L3
.L2:
mov eax, 1
.L3:
pop rbp
ret
which (if I understand correctly) means, that 2^32-1 actually equals -1.