Professor Shai Simonson - CSC304 - Computer Architecture



Assignment 1

Basic Assembly Language Using MIPS
I/O, Assignment, Selection, Loops, and Strings

 

Due   (Total 25 points)  Friday, February 9

0.  In the book.  (5 points)  Chapter 1 Exercises (at End of Chapter):  1.5, 1.6, 1.7, 1.9 (all parts)

1.  (5 points) Write a SPIM program to take three integer values A, B and C and output B2 - 4AC, if the value (B^2 - 4AC) is greater than 0, or else output 0.  You  may assume that all values fit in 32 bits.  Recall that "mul" uses three parameters and only stores the low half of the result in the "result" register, while the MIPS instruction "mult" uses only two parameters and stores its answer in registers LO and HI.   Either mul or mult can be used here because you may assume that all results fit in 32 bits.  You could hard code the data in memory in your program ( A: .word 12 etc.), but better is to read each of the three integers from the console (using 5 for $v0) and store them in A, B, and C, respectively.

2.  (5 points) Write and run a SPIM program that calculates the greatest common divisor of two integers.  You can use the "remu" unsigned remainder instruction, and implement Euclid's algorithm in a loop.

3.  (10 points) Write and run a SPIM program which takes a string as input, and outputs the same string with the first occurrence of a letter in each word in uppercase, and all other letters in lowercase. Any non-letters should remain as they are.  The string can consist of any characters up to a maximum of 100. You may assume that a new word starts after one or more spaces.
For example the string  "hhdThY        67trrEErr     UUUdd$5W  xYa" should become "Hhdthy         67Trreerr     Uuudd$5w   Xya"
 
Make sure to comment your programs carefully, and to make them user friendly to run.

back

 

shai@stonehill.edu

http://www.stonehill.edu/compsci/shai.htm