Assembly Language for Beginners

(Jeff_L) #1

1.14 Conditional jumps


xor eax, eax
ret 0
_main ENDP


However, the compiler forgot to remove the “skip me!” string.


1.13.2 Exercise


Try to achieve the same result using your favorite compiler and debugger.


1.14 Conditional jumps


1.14.1 Simple example


#include <stdio.h>


void f_signed (int a, int b)
{
if (a>b)
printf ("a>b\n");
if (a==b)
printf ("a==b\n");
if (a<b)
printf ("a<b\n");
};


void f_unsigned (unsigned int a, unsigned int b)
{
if (a>b)
printf ("a>b\n");
if (a==b)
printf ("a==b\n");
if (a<b)
printf ("a<b\n");
};


int main()
{
f_signed(1, 2);
f_unsigned(1, 2);
return 0;
};


x86


x86 + MSVC


Here is how thef_signed()function looks like:


Listing 1.106: Non-optimizing MSVC 2010

_a$ = 8
_b$ = 12
_f_signed PROC
push ebp
mov ebp, esp
mov eax, DWORD PTR _a$[ebp]
cmp eax, DWORD PTR _b$[ebp]
jle SHORT $LN3@f_signed
push OFFSET $SG737 ; 'a>b'
call _printf
add esp, 4

Free download pdf