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:
- Log in to hopper.slu.edu
- Assemble and run our template program
- Modify this program's behavior
Exercises
- 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
- 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
- Now, download the template program to Hopper with the command wget:
wget http://cs.slu.edu/~dferry/courses/csci2400/asm/template.s
- First, take a moment and look at the program in a text editor of your choice. There are only
five lines of code between the comments "Our code starts here" and "Our code ends here". Can you
describe what the first two lines do? Can you describe what the second two lines do? 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.
- There are currently two variables in this program- what are they called and what
are their values?
- What will this program print to the console?
- Assemble the program and run it with the commands:
gcc -m32 template.s -o template
./template
- 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.
- 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.
- 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)
- Did the variables print in the order you expected? Why or why not?
- Email your program to the instructor when you are done. Have a nice day!