Homeworks
-
Homework 1
Due February 7 in class
Book Problems: 2.2, 2.10, 2.12
Convert the Following C++ code to SAL:
int sum, z=10; for(int i = 0; i < z;++i){ if (i % 2 == 0) sum += 1; } -
Homework 2
Due February 16th in class.
Book Problems: 3.8, 3.9, 3.12
-
Homework 3
Due March 2nd in class.
Book Problems: 4.6, 4.7, 4.8
Convert the following values into IEEE FPS format: 4.55,-2.45,2045.625
-
Homework 4
Due March 14th in class.
Book Problems: 5.2, 5.4, 5.6, 5.7, 5.8, 5.9, 5.10, 5.11
-
Homework 5
Due April 18th in class.
Book Problems: 6.3, 6.4, 6.5, 6.11
-
Homework 6
Due May 4th in class
Book Problems: 10.2, 10.3, 10.5
Programs
-
Program 1
Due February 11th by midnight
Name program firstname_lastname.sal and email to cs215001@cs.uwm.edu. Include your full name in the body of your email message and in the comments at the beginning of the source file.
Begin by reading this. The program you will create for this first assignment will read in two values: wind speed in miles per hour and temperature in Fahrenheit. To make use of the formula on the page you read, you will need to convert the wind speed to kilometers per hour and the temperature to Celsius. Use the formula given to compute the wind chill. Output the temp in both F and C. Display the wind chill in both F and C subject to the following. If the wind speed is less than or equal to 6mph or if the temperature is above 40 degrees F, don't display the wind chill data.
Your program should run like this:
Welcome to the Weather Calulator!
Enter the temperature: 12
Enter the wind speed: 35
The temperature is 12.000000 degrees F and -11.111111 degrees C.
The windchill is -14.676857 degrees F and -25.931587 degrees C.
Welcome to the Weather Calculator!
Enter the temperature: 50
Enter the wind speed: 50
The temperature is 50.000000 degrees F and 10.000000 degrees C.
Welcome to the Weather Calculator!
Enter the temperature: 4
Enter the wind speed: 5
The temperature is 4.000000 degrees F and -15.555555 degrees C.
Welcome to the Weather Calculator!
Enter the temperature: -12
Enter the wind speed: 15
The temperature is -12.000000 degrees F and -24.444445 degrees C.
The windchill is -26.604897 degrees F and -32.558273 degrees C.
-
Program 2
Due February 25th by midnight
Name program firstname_lastname.sal and email to cs215001@cs.uwm.edu. Include your full name in the body of your email message and in the comments at the beginning of the source file.
Write a program which reads in a paragraph of up to 100 characters, performs a frequency analysis on the characters contained in the paragraph and outputs a sorted list (by ASCII value) of the number counts for each character.
- This program must use SAL procedures.
- The frequency analysis counts how many times a character occurs in the given input. If the input is "Hello World", then frequency analysis would say something like h:1, e:1, l:3, o:2, w:1, r:1, d:1, space:1. For this assignment, consider all input in lower case for the frequency analysis.
- Code must be commented.
Sample output is:
Enter a string: A man, a plan, a canal, Panama.
The frequency analysis is as follows:
space:6
,:3
.:1
a:10
c:1
l:2
m:2
n:4
p:2 -
Program 3
Due March 11th by midnight
Name program firstname_lastname.sal and email to cs215001@cs.uwm.edu. Include your full name in the body of your email message and in the comments at the beginning of the source file.
Write a basic calculator using MAL. It should support x+y, x-y, x*y, x/y, x%y, x^y and x! where x and y are integers and the output is an integer. The command to quit is q and if a statement is not understood, you should output an error message and reprompt the user for input. Some requirements are as follows:
- Write a recursive procedures to perform the exponentiation and the factorial operations.
- The program will determine from the user input, which calculation to perform. i.e. if the user enters 4^2, the program automatically knows that an exponentiation is required and likewise if the user enters 5! the program knows that factorial is required.
- The program will calculate the requested operation, display the result and prompt the user for another operation.
- Notice that x-y can cause negative output to be produced so make sure your ouput procedure will ouput the negative sign.
- Comment each function. Each parameter should be specified and the result should be specified. Also write a description of the proceedure.
A sample run of the program may look like this:
Input: 4!
Result: 24
Input: 2^5
Result: 32
Input: 12*10
Result: 120
Input: 5-43
Result: -38
Input: q
Good Bye!Extra Credit Extension (each is worth 5 extra points toward your homework score)
If you implement one or both of the extensions, note this in your email and in the comments at the beginning of your source file.
Extension 1:
- Extend the base calculator (all operations) to handle inputs of negative numbers.
- Valid inputs would be as follow: ~5, 5. For the exponentiation: ~3^2, ~2^5, etc. (we are still only doing positive powers)
- Notice that I have specified the ~ to be the negation operator so it is different from the subtraction operator.
- You will have to change the input procedure to handle the negation sign and convert the number accordingly.
- Notice that this can cause negative values to be produced, so you will have to modify the output procedure to output the negation sign for negative numbers.
Extension 2:
- Extend the exponentiation operation to handle negative exponents and display the resulting number as a fractional number.
- i.e. 2^~1 should output 1/2, 2^~3 should output 1/8 and ~3^~3 should output ~1/27.
Program 4
Due: April 8th by Midnight
Name program firstname_lastname.sal and email to cs215001@cs.uwm.edu. Include your full name in the body of your email message and in the comments at the beginning of the source file.
Write a program which takes as input a positive or negative integer and outputs the binary, octal and hex values for that integer input. The representations should be in 2's complement. The program must run in spim version 6.5 or newer (I am using version 7.1). Spim 6.5 is currently installed on the grid1 (I have put in a request to 7.1 installed). The program should loop until it recieves a 0 which causes it to quit. The program can just die with bad input.
A sample run of this program should look like:
Number: 326
Binary: 00000000000000000000000101000110
Octal: 0506
Hex: 0x146
Number: atrh
That is not a number!
Number: -217
Binary: 11111111111111111111111100100111
Octal: 037777777447
Hex: 0xffffff27
Number: q
Goodbye!
Program 5
Due: April 27th by Midnight
Step 1: Implement a INT_IN procedure which reads only characters and returns the int read in $v0 and the terminating
character in $v1. Implement a PRINT_INT procedure which takes the int to output in $a0 and outputs only characters and then returns.
Step 2: Modify the exception handler to use your procedures (with the syscalls, but only syscall codes 11 and 12).
Step 3: Write a small program to input two integers, multiply them together and display the result (or if there is overflow, to
warn the user of the overflow). You will have to use the teq $0, $0 instruction is place of the syscall in your program.
Program 6
Note: This program is worth 75 points!
Due: May 8th by Midnight
Program extension! Due: May 10th by Midnight
This program is similar to both Program 5 and Program 3.
- Implement $v0=6 as a trap instruction in the exception handler. You may only use syscall codes 11 and 12 (and 10 for exiting). Implement a FLOAT_IN proceedure to be called by the exception handler.
- A float value can take many forms. You must accept these following formats:
- There may be a + or - or no prefix. There may or may not be a decimal. There may or may not be an E or e with an exponent in base 10 following.
- +4.53
- -2.43
- 12.343
- 3
- +463
- -18
- -4.23e5
- +2.3E10
- Write a user program which allows the user to add, subtract, multiply and divide float values.
- The interface of the program should be like the interface from program 3.
- 10 points EXTRA CREDIT: implement a power function which accepts positive and negative values in both the base and exponent, accepts any float value for the base and any integer value for the exponent and outputs a float result.