程序代写代做代考 assembly mips CS 230 Spring 2020 Due: July 3rd 2020 11:59PM EDT 41 Marks Assignment 4

CS 230 Spring 2020 Due: July 3rd 2020 11:59PM EDT 41 Marks Assignment 4
All submissions are to be completed through MarkUs. The files submitted must be either plain text files (.txt), assembly language source files (.asm), or PDF files depending on the question. PDF files may be electronically generated files from LaTeX, or scanned, hand- written solutions that are readable by the markers. Review the course outline for the policy on late submissions. This assignment has two (2) pages.
1. Write a MIPS assembly language program that takes an array as input and computes the difference between the maximum value in that array and the minimum value in that array. Assume an array with no elements has a difference of zero. You can assume, at the beginning of your program, that the memory address of the start of the array is in register $1, and the number of items in the array is in register $2 (this is how the array simulator sets up your program). Place the final result of your computation in register $3.
For example: if the user entered an array with values 110, −310, 1710, at the end of your program register $3 should contain 2010 = 0x14.
To receive full marks, your code must run without errors on the array simulator avail- able on the UWaterloo student computer science server. You do not need to follow the register conventions. Format and comment your code to be readable by the markers. Submit the file a4q1.asm (10 Marks).
2. Write a MIPS assembly language program that converts a base-10 integer x into base-y. Your program should use output to display the digits of the base-y representation of the number on the screen followed by a [LF] character. You can assume 2 ≤ y ≤ 10. You can assume the value of x is in register $1 and the value of y is in register $2 at the beginning of your program (this is how twoints sets up your program). You do not need to output any subscripts.
For example: if the user entered −3510 and 8 into twoints, your program should print -43[LF]
To receive full marks, your code must run without errors on the twoints simulator available on the UWaterloo student computer science server. You do not need to follow the register conventions. Format and comment your code to be readable by the markers. Submit your assembly language source code as the file a4q2.asm (14 Marks).
Hints: consider the approach we learned about converting bases early in the course. The stack might be a useful way of storing digits to output in the correct order. The remainder of integer division with negative numbers may not be what you expect, try making them positive instead.
Page 1 of 2

CS 230 Spring 2020 Due: July 3rd 2020 11:59PM EDT 41 Marks Assignment 4
3. Write a MIPS assembly file containing two functions alpha(a,b) and beta(x,y,z). The function alpha(a,b) should return ⌊(a + ⌊ b ⌋) ÷ 2⌋. You can assume a ̸= 0. The
a
function beta(x,y,z) should treat y and z as functions that take one parameter and return the value x − ⌊y(x)/z(x)⌋. You can assume z(x) ̸= 0.
For example:
alpha(1010,2010) = 610
beta(410,q,r) = 310 where q(x) returns x2 − 2 and r(x) returns 2x.
You are welcome to add more code to your file to test these functions. We will not be marking code outside of the alpha and beta functions (however your whole file should still be neat and readable). We will run our own separate tests on your functions.
To receive full marks, your code must run without errors on any simulator available on the UWaterloo student computer science server. You must to follow the register conventions for this question. Format and comment your code to be readable by the markers. Submit your assembly language source code as the file a4q3.asm (14 Marks).
4. Consider a MIPS assembly language program that contains a function normal user() that reads input from the MIPS input address. The function normal user() groups the 8-bit ASCII characters from the input together into groups of four (making 32-bit numbers) and then pushes those 32-bit numbers onto the stack. Then normal user() calls a bunch of other functions before popping those numbers back off the stack.
There is another function in the program called secure admin() that does some- thing very important that should never be done by a user who is using the function normal user(). There is no call to the function secure admin() anywhere in the code for normal user().
Oh no! The programmer that wrote normal user() made a horrible mistake and forgot to pop the final group of four ASCII characters (the final 32-bit number) off the stack! This was the last thing that normal user() does before it loads register $31 back off the stack and ends the function with jr $31 as usual.
How could an evil user, who is only allowed to type input into normal user(), take ad- vantage of this mistake to trick the program into running the secure admin() function even though it was not supposed to? You can assume the entire program is stored in memory at addresses less than 231. You can assume the evil user can read the program’s assembly language source code, but cannot modify it.
Submit the file a4q4.pdf or a4q4.txt (3 Marks).
Page 2 of 2