Lab 10 - Assembler 1

This lab is not submitted.

You might be helped with this assembler summary.

To generate assembly from the compiler, use the -S switch instead of the -c switch. That will generate a .s file with the assembly in it.

For example,
    gcc -S foo.c
will create a file called foo.s that will contain assembly for the c code in foo.c

If your machine is configured to run 64 bit code, you will need to add the -m32 switch to get the compiler to generate code that is like we have been using in class.

1) Minimum

Write a file min.c that contains a simple function min that takes three ints and returns the minimum of the three. Do not include a main function.

Generate the min.s file and comment it, identifying where each parameter or variable is stored and what each instruction does.

2) hello world

Write a hello.c file that contains two functions.

The function sayHello should take a single string (char *) parameter and write the message "hello" followed by the value passed in.

So if you call sayHello("world"), the result should print
    hello world

You should use printf to do the printing.

The function main should call sayHello("world") as its only work.

Make sure your hello can be compiled all the way and correctly runs.

Generate hello.s and comment it as above. Note that the compiler can do some different things for main.

3) Goodbye

Modify your hello.s file to make it say goodbye instead of hello.

Compile it with gcc (you can do -c with a .s file) and link it normally to try running it.