CS201 Lab: Control Flow Structure
Objective of this lab:
To investigate the Control Flow Structure and implement them in Spim.
You will learn how to use assembly language to implement an "if statement"
and a "loop".
Preparation
Read lab lecture notes.
Lab Assignment
Please note:
To make it easier for marking, you are required to submit
one .pdf file and all the .s files.
The .pdf file will contain all the required components for the lab assignment.
This will apply to Lab #7 to Lab #10.
Program#1:(Will be arked)
Write a SPIM assembly language program convert.s.
The program will do the following:
- Prompt the user to enter a letter indicating Celsius or Fahrenheit
- C or c indicates that temperature entered is in Celsius.
Prompt the user to enter an integer indicating the temperature in Celsius,
and convert it to Fahrenheit and print out the converted temperature.
- F or f indicates that temperature entered is in Fahrenheit.
Prompt the user to enter an integer indicating the temperature in Fahrenheit,
and convert it to Celsius and print out the converted temperature.
- If the letter entered is not C, c, F, or f, print out
error message "Wrong Letter!".
- Here are the two formulas for your reference.
F = (9 * C / 5) + 32
C = 5 * (F - 32) / 9
Print out the converted values with appropriate message.
Testing wrong letters: G and h
Testing values for C or c: 100, 0, 50
Testing values for F or f: 212, 0, 50
Program#2:
Write a SPIM assembly language program equationLoop.s based on the
example program math1.s in the previous lab notes.
The program will do the following three things for 5 times:
- Prompt the user to enter a value for X each time.
(The recommended testing values for X are 7, 5, 9, 6, and 2.)
- Calculate the corresponding result of this expression A*X^2+B*X+C.
- Print out the calculted result with appropriate message.
You will hand in the following:
- The source code in the file convert.s and equationLoop.s.
- The screenshot to show the screen right after you loaded the .s file.
- The screenshot of the console displaying the results for the corresponding input values.
Copyright: Department of Computer Science, University of Regina.