Lab7: Introduction to Assembly
Programming
Goal
In this lab you will start writing simple programs in x86-64 assembly
language.
References
Here are some good references that can help you in your programming
Introduction
You will write a few small assembly language functions that will
be
invoked from "C".
For each program write a comment for each line of assembly language you
write.
You may use "gcc -S" to compile simpe c programs to look at the
assembly code generated. However, you
need to write the programs yourself. Do not submit the assembly code
generated by the compiler. It is easy to tell what programs where
generated by the compiler and what programs you have written yourself.
Getting the sources
Download the file lab7-src.tar.Z.
Uncompress it and untar it.
uncompress lab7-src.tar.Z
tar -xvf lab7-src.tar
You will use the files here to start your implementation and to test it.
The Makefile already includes all the instructions you need to build
your assembly functions and to test them.
Just type "make".
Program 1.
In the file myadd.s write a function int add(int a, int b,
int c) that adds three numbers a, b, and c and returns the
result.
Test the program by linking it with myaddtest.c.
Program 2.
In the file mystrlen.s write a function int mystrlen(char *s)
that computes the length of a string. Use the mystrlentest.c program to
test this function.
Program 3.
In the file addarray.s implement the function int addarray(int n, int * array)
that add all the elements of the array passed as parameter. n is the
length of the array. Use the addarraytest.c program to test your
application.
Program 4.
In the file factorial.s implement the function double fact(int n) that
obtains the factorial of n. Use the program factorialtest.c to test
your implementation.
Program 5.
Write a complete program sort.s in assembly code that includes main()
that reads from standard input integer numbers one in each line until
EOF is detected and then sorts them using bubble sort. Then it prints
the numbers in sorted order. You may call scanf("%d", &val) in
assembly language or any other functions you need.
Example:
gcc -o sort sort.s
sort
2
3
1
7
4
6
<ctrl-d>
Sorted:
1
2
3
4
6
7
Turnin
Follow these instructions to turnin lab7:
- Make sure that your programs are built by typing "make".
Make sure it builds and runs in one of the machines sslab01.cs,
sslab02.cs etc.
- Type "turnin -c cs250 -p lab7 lab7-src"
- Type "turnin -c cs250 -p lab7 -v" to make sure you have
submitted the right files
The deadline of this project is 11:59pm Thursday October 31st.