CSCI-2500 Computer Organization

Fall 2000

Homework 1
Due Date: Sep 25th (received by midnight)

Submission Instructions


This homework involves writing a number of C programs that are used to test how long it takes to perform simple arithmetic operations. You also need to write a C program that can run the unix time command on any of the arithmetic programs, so you can measure how long it takes to run them (and so you get some experience playing with exec()). All code must be in C (no shell scripts please)!

Part 1) individual arithmetic operation test programs

Integer Addition program

Write a program that accepts a single command line argument that specifies the number of integer addition operations that should be done. The program should then perform the specified number of integer addition operations and then exit. No output should be generated by this program. Here is what it might look like to compile and run the program (I called mine iadd.c), including using the unix time command to see how long it takes:

> gcc -o iadd iadd.c
> ./iadd 
ERROR: ./iadd needs a count
> ./iadd 10000
> time ./iadd 10000

real    0m0.011s
user    0m1.003s
sys     0m0.004s

> time ./iadd 100000000

real    0m2.738s
user    0m1.661s
sys     0m0.009s

Multiplication and Floating Point ops

Write 3 similar programs, one that does integer multiplication, one that does floating point addition and one that does floating point multiplication. In all cases, do your best to minimize the code that is not part of the specific arithemtic operations being measured (don't add a lot of other stuff!). I named my programs like this:

All four programs should accept a single command line parameter that indicates the number of operations to be done.

Part 2) Wrapper program

Write a program that does the following:

Your wrapper program can either exit once the measurement is made (as will be the case if it calls exec directly) or can continue to prompt the user for another operation/count (to accomplish this you will need to have the wrapper program fork, and then have the child do the exec - the parent can just go back and ask the user for the next test.

I named my wrapper program hw1.c, and here is what it looks like when I run the program:

> ./hw1
Select desired operation:
 1      Integer addition
 2      Integer multiplication
 3      Floating point addition
 4      Floating point multiplication
1
Enter number of iterations
100000000
Spawning ./iadd 100000000

        2.38 real         2.35 user         0.00 sys
> ./hw1
Select desired operation:
 1      Integer addition
 2      Integer multiplication
 3      Floating point addition
 4      Floating point multiplication
3
Enter number of iterations
100000000
Spawning ./fadd 100000000

        2.69 real         2.69 user         0.00 sys
>

Deliverables

Your submission must include the following:

Submission Instructions

Submission Instructions are here. Please make sure you send submissions to comporg-submit@cs.rpi.edu not to comporg@cs.rpi.edu!!!