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.outunless 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 |
---|
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: |
---|