CSCI 2400: Assembly Class 1

Hello, world!


Welcome to assembly programming! Let's get started with a simple "Hello, world!" program.

In today's class you will:

  1. Log in to hopper.slu.edu
  2. Assemble and run our template program
  3. Modify this program's behavior

Exercises

  1. First we need a Linux environment, so we will remotely connect to the department server at hopper.slu.edu. Alternatively, you can login locally and then also connect to hopper so that you can always access your work remotely. In general you will only ever need Linux terminal access for these exercises, though you're welcome to use NoMachine if you'd like the GUI desktop. If you're using one of the classroom machines, login by typing at a terminal:

    ssh username@hopper.slu.edu

  2. Make a new directory for your work with the command mkdir new_dir_name, then change to that directory with the command cd new_dir_name

  3. Now, download the template program to Hopper with the command wget:

    wget http://cs.slu.edu/~dferry/courses/csci2400/asm/template.s

  4. First, take a moment and look at the program in a text editor of your choice. There are only a few lines of code between the comments "Our code starts here" and "Our code ends here". Can you describe what the first set of lines does? Can you describe what the second set of lines does? If you can't, try to remember the "program stack" that we talked about in class. If you're still not clear, call the instructor over to explain.

  5. There are currently two variables in this program- what are they called and what are their values?

  6. What will this program print to the console?

  7. Assemble the program and run it with the commands:

    gcc -m32 template.s -o template

    ./template

  8. Change the output of the program by modifying the variable "string" and the variable "a". Make sure that you still print the value of the variable "a". Re-assemble and re-run your program to make sure it works correctly.

  9. Now change the output of your program by inserting an addl instruction before the first pushl instruction. The first operand should be an immediate instruction, and the second operand should be the variable name "a" without dollar signs or percent signs.

  10. Modify your program so that it contains a second variable named "b", and so that your program prints both the value of a and b. (Use a single call to printf)

  11. Did the variables print in the order you expected? Why or why not?

  12. Keep your program for submission with the next homework. Have a nice day!