.
(Microsoft Visual Studio):
; File tmp.c
; Line 5
push ebp
mov ebp, esp
push ecx
; Line 6
mov BYTE PTR _i$[ebp], -128 ; ffffff80H
; Line 7
movsx eax, BYTE PTR _i$[ebp]
neg eax
mov BYTE PTR _i$[ebp], al
; Line 8
movsx ecx, BYTE PTR _i$[ebp]
push ecx
push OFFSET FLAT:$SG775
call _printf
add esp, 8
; Line 9
xor eax, eax
; Line 10
mov esp, ebp
pop ebp
ret 0
_main ENDP
.
And remember your double complement arithmetic.
Does it make sense?
====== ADD ======
It is really very simple. Here is a slightly modified example that may help clarify:
int
main (int argc, char *argv[])
{
int i=-128, j, k, l;
char c = i;
printf("i: %d == 0x%x; c: %d == 0x%x\n", i, i, c,c);
j=-i;
k=~i;
l=0-i;
i=-i;
c=-c;
printf("%d, %d, %d, %d, %d\n",i,j,k,l,c);
printf("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",i,j,k,l,c);
return 0;
}
Results:
i: -128 == 0xffffff80; c: -128 == 0xffffff80
128, 128, 127, 128, -128
0x80, 0x80, 0x7f, 0x80, 0xffffff80