CSE 4105 System Programming · Lab 2

Machine and Assembly Language

Your first nasm programs; reading the assembly gcc makes from C.

Tasks

The same steps as the lab slide. Do them on a Linux PC with the files from the zip; the tools below help you check your thinking first.

Lab 2 · Machine and Assembly Language

  1. Hand-assemble
    Encode LDA ALPHA, STCH BUFFER,X and TIX MAXLEN (ALPHA = 1033, BUFFER = 1039, MAXLEN = 1036). Show all six steps.
  2. Trace on paper
    Trace Program 2 (string copy) with the string "CAT" and FIVE replaced by THREE. Write X, A and CC after every instruction.
  3. Read gcc output
    gcc -O0 -S sumto.c. Mark which lines are s = 0, i = 1, i <= n, s += i, i++. Repeat with -masm=intel.
  4. Build hello.asm
    Type it, build with nasm and ld, run it. Change the message. Run strace and count the calls.
  5. Build sum.asm
    Change it to add 1 … 20. Check the answer with echo $?. Step through two rounds in gdb.
  6. Break it on purpose
    Remove the exit syscall, then global _start. Record each message and explain it in one sentence.

Submit: your lab notebook with commands, outputs, the trace table from task 2, and one sentence per task.

Try it here

These run in your browser, with no server and no internet. They are built from the same reference programs as the lab, so their output matches what your finished C program should print. They do not replace the real lab: the kernel, gcc and your own code are the point.

Read the files

Every text file from lab02_files.zip. Read here, then download the zip to work on them.

    ← Lab 1All lecturesLab 3 →