Ray Ontko
Department of Computer Science
Earlham College
The purpose of this lab is to give you a chance to examine and modify assembly language programs.
Imagine that you are working on a program with a time-critical portion which you would like to improve. Your program (written in C) is using a "trial division" approach to factoring primes, and at one point you calculate both the quotient (/) and remainder (%). You recall (from your computer organization course in college) that the 80386 has an instruction which computes both simultaneously during division and wanted to find out if the compiler is using this optimal approach, and if not, fix it.
So, you wrote a small test program, divrem.c, to see how the compiler handles the situation:
/*
divrem.c
A test program to investigate performance improvements
in programs containing / (div) with % (rem).
Ray Ontko, 04/16/2000
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i ;
int a ;
int b ;
int q ;
int r ;
a = 23 ;
b = 5 ;
for ( i = 0 ; i < 100000000 ; i ++ )
{
q = a / b ;
r = a % b ;
}
printf( "a %d b %d q %d r %d\n", a , b , q , r ) ;
exit( EXIT_SUCCESS ) ;
}
Using this program, do the following:
cc divrem.c -o divrem
time ./divrem /usr/bin/time ./divremMake note of the different execution statistics given.
cc -S divrem.cThis produces a file "divrem.s" which contains the assembly language equivalent of your original program.
rm divrem cc divrem.s -o divrem time ./divrem /usr/bin/time ./divremHere we delete the originally compiled version of the C program, assemble and link "divrem.s" to the file "divrem", and finally re-run the program. Again, note the timing statistics. How do they compare to the initial run?
rm divrem cc divrem.s -o divrem time ./divrem /usr/bin/time ./divremShow your program and explain your results to the person next to you.
Copyright © 1997, 2000, Ray Ontko (rayo@ontko.com). All rights reserved.