unsigned int i=-2;
std::cout<<std::hex<<i<<"\n";
return i;
mov eax,115; "sum"If sum is less than 100, then the program jumps to sum_is_small. The trouble is if the "jl" does *not* jump, then the program just keeps running along to... sum_is_small! So this will print no matter what value sum has. The fix is to put in a jump or return after the jl, to handle the "else" case of the if:
cmp eax,100
jl sum_is_small
sum_is_small:
push eax
extern print_int
call print_int
pop eax
ret
mov eax,115; "sum"And this is probably best written as a jump-if-greater-or-equal, like:
cmp eax,100
jl sum_is_small
jmp it_aint_small
sum_is_small:
push eax
extern print_int
call print_int
pop eax
it_aint_small:
ret
mov eax,115; "sum"
cmp eax,100
jge it_aint_small
push eax
extern print_int
call print_int
pop eax
it_aint_small:
ret
mov eax,DWORD[myInt+4] ; read this int into eax
ret
myInt:
dd 0xa3a2a1a0 ; first int, pointed to by "myInt"
dd 0xb3b2b1b0 ; second int, 4 bytes higher than "myInt"
This returns 0xb0a3a2a1, because we're on a little-endian machine:
mov eax,DWORD[myInt+1] ; read this int into eax
ret
myInt:
dd 0xa3a2a1a0 ; first int, pointed to by "myInt"
dd 0xb3b2b1b0 ; second int, 4 bytes higher than "myInt"