COSC 065 Hardware Systems

Fall 2006

Homework Assignment #5

PowerPC Assembly Language

Due: Wednesday, November 01, 12:00PM CDT
Work may be completed in pairs.
Background:

Take time to familiarize yourself with the UNIX environment, using the tutorial here.

Always start your assignments using the template here.

Your work must be assembled and run on Morbius (morbius.mscs.mu.edu). You may make use of the helper I/O functions getnum, printnum, and printhex in the cosc065.s file, but you should no longer need them.

Assemble your programs on Morbius using the command:

gcc <myfile.S>

Run your programs on Morbius using the command:

./a.out
unless you have used the "-o" option to gcc to change the name of your assembled executable.

Few rules govern the format of assembly language programs. Make an effort to keep your programs readable and well-documented; sometimes the professor gives partial credit if he can tell what you were trying to do, even if it doesn't quite make it.
Q1 - Calculator

Write an assembler program that reads in arithmetic operators ("+", "-", "*", "/" and "%") and pairs of integers and returns the result of applying the operators. Continue looping until the end of file marker is reached, as discussed in class.

The professor has provided an example program for your reference, runnable on Morbius as ~brylow/cosc065/bin/hw5-calc.

You may assume that overflow and underflow do NOT occur.
Q2 - Kelvin Table

Write an assembler program that reads two positive integers, low and high, and prints a table of conversions from temperature degrees Kelvin to degrees Celsius and degrees Fahrenheit every five degrees Kelvin from low to high.

The professor has provided an example program for your reference, runnable on Morbius as ~brylow/cosc065/bin/hw5-kelvin.

Use the operating system's printf() function to format your output.
Q3 - GCD

Write an assembler program that reads two positive integers, x and y, and prints the greatest common divisor of x and y. Continue looping until the end of file marker is reached, as discussed in class.

The professor has provided an example program for your reference, runnable on Morbius as ~brylow/cosc065/bin/hw5-gcd.

You may assume that overflow and underflow do NOT occur.
Q4 - The Joy of Assembly
Using the documentation for the PowerPC processor, manually assemble the last five instructions of your program (in the template epilog) into machine language. That is, show the binary encoding of these instructions that the machine will actually fetch and execute.

Show your work, and carefully label the various fields for each line of code.

The primary documentation for the opcodes can be found in chapter 8 of the PowerPC reference manual, "Instruction Set". Some of the opcodes in our assembly language are shortcuts for other actual opcodes; these are documented in appendix F, "Simplified Mnemonics".
Q5 - Activation Records

The Fibonacci number example used in class is compiled into the assembly language program here: fib.S. (Because this code was translated to assembly by a compiler, which is itself just a program, the assembly code is not commented and may not be the most effective solution.)

Draw out the activation records that this program has on the stack when at its largest point, assuming fib() was called with a parameter of "4". Label all of the locations in the stack that you can identify, complete with their contents. Because the compiler is not always optimally efficient, there may be unused/unlabeled locations.
What to turn in:

  • E-mail your assembly source files to the professor with a subject header "COSC 065 HW#5".
  • Be certain to put both team member names on work submitted. It would be courteous to carbon-copy your teammate when e-mailing the final submission.
  • Turn in the written component (Q4 and Q5) as hardcopy at the beginning of lecture.
    Back