created 07/07/2003; edited 05/31/2015


Chapter 27 Programming Exercises


NOTE: Use the Stack-based Linkage Convention for these programs.

In the Settings menu of SPIM set Bare Machine OFF, Allow Pseudo Instructions ON, Load Trap File ON, Delayed Branches ON, Delayed Loads ON, Mapped IO ON, Quiet OFF.


Exercise 1 — Same String

Write a program that prompts the user for a string. The program reads in the string and then prompts for another string and reads it in. Then the program writes a message that says if the two strings are character-by-character identical.

Use at least three routines (counting main) for this.

Click here to go back to the main menu.


Exercise 2 — Same String, Improved

Modify the program in Exercise 1 that the program inputs two strings and writes out a third string. The third string has a blank in positions where the two characters are identical and has a "*" in positions where the characters are not identical.

Click here to go back to the main menu.


Exercise 3 — Triangle or Square

Write a program that asks if the user wants a triangle or a square. It then prompts for the size of the object (the number of lines it takes to draw the object). The program then writes a triangle or a square of stars ("*") to the monitor.

*******
*******
*******
*******
*******
*******
*******

or

*
**
***
****
*****
******
*******

Write a subroutine for each figure. In them, use a subroutine starline that writes a line of a given number of stars.

Click here to go back to the main menu.


End of Exercises