Assembly Language for Beginners

(Jeff_L) #1

1.14. CONDITIONAL JUMPS


jmp puts
.L1:
rep ret
.L7:
mov DWORD PTR [esp+4], OFFSET FLAT:.LC1 ; "a==b"
jmp puts


We also seeJMP putshere instead ofCALL puts / RETN.


This kind of trick will have explained later:1.15.1 on page 154.


This type of x86 code is somewhat rare. MSVC 2012 as it seems, can’t generate such code. On the other
hand, assembly language programmers are fully aware of the fact thatJccinstructions can be stacked.


So if you see such stacking somewhere, it is highly probable that the code was hand-written.


Thef_unsigned()function is not that æsthetically short:


Listing 1.110: GCC 4.8.1 f_unsigned()

f_unsigned:
push esi
push ebx
sub esp, 20
mov esi, DWORD PTR [esp+32]
mov ebx, DWORD PTR [esp+36]
cmp esi, ebx
ja .L13
cmp esi, ebx ; this instruction could be removed
je .L14
.L10:
jb .L15
add esp, 20
pop ebx
pop esi
ret
.L15:
mov DWORD PTR [esp+32], OFFSET FLAT:.LC2 ; "a<b"
add esp, 20
pop ebx
pop esi
jmp puts
.L13:
mov DWORD PTR [esp], OFFSET FLAT:.LC0 ; "a>b"
call puts
cmp esi, ebx
jne .L10
.L14:
mov DWORD PTR [esp+32], OFFSET FLAT:.LC1 ; "a==b"
add esp, 20
pop ebx
pop esi
jmp puts


Nevertheless, there are twoCMPinstructions instead of three.


So optimization algorithms of GCC 4.8.1 are probably not perfect yet.


ARM


32-bit ARM


Optimizing Keil 6/2013 (ARM mode)


Listing 1.111: Optimizing Keil 6/2013 (ARM mode)

.text:000000B8 EXPORT f_signed

Free download pdf