Assembly Language for Beginners

(nextflipdebug2) #1

.1. X86


JNEAKAJNZ: jump if not equal or not zero: ZF=0

JNGEjump if not greater or equal (signed): SF≠OF

JNGjump if not greater (signed): ZF=1 or SF≠OF

JNLEjump if not lesser (signed): ZF=0 and SF=OF

JNLjump if not lesser (signed): SF=OF

JNOjump if not overflow: OF=0

JNSjump if SF flag is cleared

JNZAKAJNE: jump if not equal or not zero: ZF=0

JOjump if overflow: OF=1

JPOjump if PF flag is cleared (Jump Parity Odd)

JPAKAJPE: jump if PF flag is set

JSjump if SF flag is set

JZAKAJE: jump if equal or zero: ZF=1

LAHFcopy some flag bits to AH:
7 6 4 2 0


SFZF AF PF CF

This instruction is often used inFPU-related code.

LEAVEequivalentoftheMOV ESP, EBPandPOP EBPinstructionpair—inotherwords, thisinstructionsets
thestack pointer(ESP) back and restores theEBPregister to its initial state.


LEA(Load Effective Address) form an address


This instruction was intended not for summing values and multiplication but for forming an address,
e.g., for calculating the address of an array element by adding the array address, element index,
with multiplication of element size^5.

So, the difference betweenMOVandLEAis thatMOVforms a memory address and loads a value from
memory or stores it there, butLEAjust forms an address.

But nevertheless, it is can be used for any other calculations.

LEAis convenient because the computations performed by it does not alterCPUflags. This may be
very important forOOEprocessors (to create less data dependencies).

Aside from this, starting at least at Pentium, LEA instruction is executed in 1 cycle.

int f(int a, int b)
{
return a*8+b;
};

Listing 1: Optimizing MSVC 2010
_a$ = 8 ; size = 4
_b$ = 12 ; size = 4
_f PROC
mov eax, DWORD PTR _b$[esp-4]
mov ecx, DWORD PTR _a$[esp-4]
lea eax, DWORD PTR [eax+ecx*8]
ret 0
_f ENDP

Intel C++ uses LEA even more:

int f1(int a)
{
return a*13;
};

(^5) See also:wikipedia

Free download pdf