x86 Assembly

CS 301 Lecture, Dr. Lawlor, 2005/09/23

Last lecture we saw what basic assembly looked like.  Where do you find the rest of the registers and instructions?

As usual, by reading a manual!  The Intel Software Developer's Manuals are incredibly long, boring, and complete--they give all the nitty-gritty details. Volume 1 lists the processor registers in section 3.4.1. and is what you need for all x86 instructions.  Volume 2 lists all the instructions.

In summary, the basic registers are:
eax
ecx
edx
ebx
esi
edi
ebp
esp
Be careful using ebp and esp, though--they're used for subroutine calls (as we'll talk about later).

Some useful instructions are:
Mnemonic
Purpose
Examples
mov src,dest
Move data between registers, load immediate data into registers, move data between registers and memory.
mov $4,%eax  # Load constant into eax
mov %eax,%ebx  # Copy eax into ebx
mov %ebx,123  # Copy ebx to memory address 123
add src,dest
dest=dest+src
add %ebx,%eax # Add ebx to eax
mul src
Multiply eax and src as unsigned integers, and put the result in eax.  High 32 bits of product go into eax.
mul %ebx #Multiply eax by ebx
jmp label Goto the instruction label:.  Skips anything else in the way. jmp post_mem
mov %eax,0 # Write to NULL!
post_mem: # OK here...
cmp a,b

Compare two values.  Sets flags that are used by the conditional jumps (below).  WARNING: compare is relative to *last* argument, so "jl" jumps if b<a!
cmp $10,%eax  
jl label Goto label if previous comparison came out as less-than.  Other conditionals available are: jle (<=), je (==), jge (>=), jg (>), jne (!=), and many others. jl loop_start  # Jump if eax<10

You've now seen enough instructions to be able to do everything you could do in UEMU on the real machine!