NetRun & Real Assembly

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

Grab an account from:
This will email you your account password (to a UAF email address).
(NOTE: I'm hacking on NetRun pretty extensively, so be sure to let me know if you find any bugs or have suggestions for making it work better.)

Log in, and try it out now:
    mov $4,%eax    # Comment

This is GNU assembly code for x86, which you'll have to select from the dropdowns.  You can also just click on the assembly.

Ok, so this returns 4.  Why--what the heck does this mean?  Let's look at it piece by piece:
How is this different from C?  Well, like most assemblers,
All the assembler does is take this line, and spit out the corresponding machine code.  NetRun disassembles the resulting code as:
Disassembly of section .text:

00000000 <foo>:
0: b8 04 00 00 00 mov $0x4,%eax
5: c3 ret
The x86 "mov 32-bit immediate value into register eax" instruction opcode is 0xB8.  It's followed by the 32-bit (4-byte) value to move, stored in the little-endian byte order that is standard on x86, so the "04" comes first followed by the higher-value bytes which are zeros.

Next class, we'll see quite a few other x86 registers & instructions, to do useful stuff in assembly.