Spring 2001 CSCI 255 Lab 10

This lab is scheduled for the week of 2 April - 4 April.

Goals and Methods

This week we'll look at:

  1. Finishing out subroutine program
  2. Writing IA-32 assembly code

Finish up some old work

If you haven't finished Lab 9, do so now. Leave your work in the csci/255/lab9 directory you created last week.

Introduction to IA-32 programming

We have three short tasks for you this week. Begin by executing the following commands to create a directory csci/255/lab10 and copy seven files into it.

Notice that one of these files is a Makefile, a special Unix control file for compiling (and assembling) programs. To compile files within your directory type the following command:

This command will run the C compiler, gcc, twice to compile the C programs main10a.c and main10b.c. It will run an assmbler, nasm, four times. It will also run the linker twice, also using gcc, to produce the executable programs lab10a and lab10b.

You've built the program lab10a. Now run it by typing:

Looks familiar. It's the Lab 9 program. However, something seems to be wrong. Take a look at the main routine for lab10. It's written in C. Now look at its two assembly subroutines, readdec and prnthex. You're going to have to modify them.

Next run main10b. Note that its output isn't quite right. It also has a main routine and two assembly subroutines, addmult and the buggy multadd.

Optimizing the code

We'll start with the readdec assembly routine. Start pico and read in the file readdec.asm. Your jobs is to improve this assembly routine, which incidently was produced by the gcc compiler, by removing at least one line of code. This isn't so hard. Just keep in mind that, unless you're getting ready to make a conditional branch, there's no point in a mov if the source and destination are the same.

Bring order to chaos

Now we'll look at the prnthex routine. Load prnthex.asm into your pico. You'll notice that right in the middle of the program that six lines of assembly code have been rearranged by accident. You're job is to get them back in the right order. The C code at the top of the file should be a bit help. There are only 720 possibilites, so you should finish before next week.

You can use the program make to recreate lab10a and then test your work.

Fixing another bug

Finally, we turn our attention to the lab10b program and its buggy multadd routine. pico multadd.asm and examine the code. This program is supposed to compute (W*X)+(Y*Z) but instead it is computing (W+X)*(Y+Z). Fix the problem, recreate lab10b, and test your work.

Going home

Do not delete your files. Your lab instructor will examine them later. Your instructor can also verify that you have placed your code in the correct place by executing the following command on woodfin.