13 September 2012

masih signed dan unsigned

Kes 1
c code:
unsigned int a = 5;
signed int b = -1;
if(a > b)
assembly code:
mov DWORD PTR [esp+24], 5
mov DWORD PTR [esp+28], -1
mov eax, DWORD PTR [esp+28]
cmp eax, DWORD PTR [esp+24]
jae .L2


Kes 2
c code:
     signed int a = 5;
     signed int b = -1;
     if(a > b)

assembly code:
        mov     DWORD PTR [esp+24], 5
        mov     DWORD PTR [esp+28], -1
        mov     eax, DWORD PTR [esp+24]
        cmp     eax, DWORD PTR [esp+28]
        jle     .L2 



Kesimpulan:
jika a dan b adalah signed int, maka compiler akan guna jle.
Tapi jika salah satu unsigned int, maka compiler akan guna jae(sebab eax = esp+28 instead +24)

No comments:

Post a Comment

Terima kasih