Assembly Language for Beginners

(Jeff_L) #1
.1. X86
7 6 5 4 3 2 1 0

7 6 5 4 3 2 1 0 CF

Despite the fact that almost allCPUs have these instructions, there are no corresponding operations
in C/C++, so the compilers of thesePLs usually do not generate these instructions.

Fortheprogrammer’sconvenience,atleastMSVChasthepseudofunctions(compilerintrinsics)_rotl()
and_rotr()^11 , which are translated by the compiler directly to these instructions.

SALArithmetic shift left, synonymous toSHL

SARArithmetic shift right

7 6 5 4 3 2 1 0

7 6 5 4 3 2 1 0 CF

Hence, the sign bit always stays at the place of theMSB.

SETccop: load 1 to operand (byte only) if the condition is true or zero otherwise. The condition codes
are the same as in the Jcc instructions (.1.6 on page 1027).

STC(M) set CF flag

STD(M) set DF flag. This instruction is not generated by compilers and generally rare. For example, it
can be found in thentoskrnl.exeWindows kernel file, in the hand-written memory copy routines.

STI(M) set IF flag

SYSCALL(AMD) call syscall (6.3 on page 747)

SYSENTER(Intel) call syscall (6.3 on page 747)

UD2(M) undefined instruction, raises exception. Used for testing.

XCHG(M) exchange the values in the operands

This instruction is rare: compilers don’t generate it, because starting at Pentium, XCHG with address
in memory in operand executes as if it has LOCK prefix ([Michael Abrash,Graphics Programming
Black Book, 1997chapter 19]). Perhaps, Intel engineers did so for compatibility with synchronizing
primitives. Hence, XCHG starting at Pentium can be slow. On the other hand, XCHG was very popular
in assembly language programmers. So if you see XCHG in code, it can be a sign that this piece of
code is written manually. However, at least Borland Delphi compiler generates this instruction.

FPU instructions

-Rsuffixinthemnemonicusuallyimpliesthattheoperandsarereversed,-Psuffiximpliesthatoneelement
ispoppedfromthestackaftertheinstruction’sexecution,-PPsuffiximpliesthattwoelementsarepopped.


-Pinstructions are often useful when we do not need the value in the FPU stack to be present anymore
after the operation.


FABSreplace value in ST(0) by absolute value in ST(0)

FADDop: ST(0)=op+ST(0)

FADDST(0), ST(i): ST(0)=ST(0)+ST(i)

FADDPST(1)=ST(0)+ST(1); pop one element from the stack, i.e., the values in the stack are replaced by
their sum

FCHSST(0)=-ST(0)

FCOMcompare ST(0) with ST(1)

FCOMop: compare ST(0) with op

FCOMPcompare ST(0) with ST(1); pop one element from the stack

(^11) MSDN

Free download pdf