Assembly Language for Beginners

(nextflipdebug2) #1

1.14. CONDITIONAL JUMPS


Here is the modified code:


Figure 1.41:Hiew: let’s modify thef_unsigned()function

If we miss to change any of these jumps, then severalprintf()calls may execute, while we want to
execute only one.


Non-optimizing GCC


Non-optimizing GCC 4.4.1 produces almost the same code, but withputs()(1.5.4 on page 21) instead
ofprintf().


Optimizing GCC


An observant reader may ask, why executeCMPseveral times, if the flags has the same values after each
execution?


Perhaps optimizing MSVC cannot do this, but optimizing GCC 4.8.1 can go deeper:


Listing 1.109: GCC 4.8.1 f_signed()

f_signed:
mov eax, DWORD PTR [esp+8]
cmp DWORD PTR [esp+4], eax
jg .L6
je .L7
jge .L1
mov DWORD PTR [esp+4], OFFSET FLAT:.LC2 ; "a<b"
jmp puts
.L6:
mov DWORD PTR [esp+4], OFFSET FLAT:.LC0 ; "a>b"

Free download pdf