Actual Assembly-- NASM

CS 301 Lecture, Dr. Lawlor

So check out "Assembly-NASM" mode in NetRun.    Here's the cheat sheet for x86 assembly.

A typical line of assembly code looks like this:
	mov eax,1234 ;  I'm returning 1234, like the homework says...
There are several parts to this line:
Unlike C/C++, assembly is line-oriented, so the following WILL NOT WORK:
	mov eax,
1234 ; I'm returning 1234, like the homework says...
Yup, line-oriented stuff is indeed annoying.  Be careful that your editor doesn't mistakenly add newlines!

Registers

The really important registers:
All the other registers:
Size
Register names
Meaning (note: not the official meanings!)
Introduced in
8-bit
al,ah, bl,bh, cl,ch, dl,dh
"Low" and "High" parts of bigger registers
1972, Intel 8008
16-bit
ax, bx, cx, dx, si, di, sp, bp
"eXtended" versions of the original 8-bit registers
1978, Intel 8086/8088
32-bit
eax, ebx, ecx, edx, esi, edi, esp, ebp
"Extended eXtended" registers
1985, Intel 80386
64-bit
rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp,
r8, r9, r10, r11, r12, r13, r14, r15
"Really eXtended" registers
2003, AMD Opteron / Athlon64
2004, Intel EM64T CPUs

x86 is rather unique in that all the smaller registers from bygone eras are still right there as *part* of the new, longer registers.  So for example, this routine returns 0x0000AB00, because 0xAB is put into byte 1 of eax:
	xor eax,eax ; Clear eax, by xor'ing it with itself.
mov ah,0xAB ; eax is return result register.

Opcodes

A list of all possible mnemonics can be found in: The really important opcodes are listed in my cheat sheet.  Most programs can be writen with mov, add, sub, mul, call, ret, cmp, jmp, jl/je/jg/..., push, and pop.