CS计算机代考程序代写 mips assembly algorithm assignment 1

assignment 1
Marina Schmidt July 11, 2021
Due Date: July 19, 2021 8:00 pm – Late assignments will not be accepted. All assignment submissions must use the Moodle online submission system
Need to show all your work and units to obtain full marks Total Marks 42 marks
1. (8 marks) Convert the following to signed binary in 8 bits 2’s compliment
i. -12810 ii. 7210
iii. 12710 iv. 125
2. (12 marks) Evaluate the following expressions, in which each operand is an 8 bit 2’s complement number, using the standard binary addition algorithm. As well as showing each result in 8 bit 2’s complement, also convert and express each as a signed decimal number. Note that whenever there is signed overflow your answer will not be correct. For which expression(s) does this occur?
i. 1111 1111 – 0111 1111 ii. 1100 0101 – 0100 0100 iii. 1010 1010 + 0111 0111 iv. 0100 1100 + 1110 0011
3. (10 marks) Outline the machine language instruction format (i.e., describe how the machine language instruction is divided into fields and state what each field is used for), and give the decimal (base10) value of each field, for each instruction in the following block of code. Assume that the code begins at memory address 500010. If you are unsure of the format of an instruction, Mr. Google may lend you a hand (he’s a helpful guy!) https://en.wikibooks.org/wiki/MIPS_Assembly/Instruction_Formats con- tains instructions formats, and opcodes (in HEX). http://www.cs.uwm. edu/classes/cs315/Bacon/Lecture/HTML/ch05s03.html contains register numbers.
loop: bne $s0, $s1, out
1

sw $s2, 4($s1)
addu $s1,$s1, $t0
j loop
out: ori $t2, $s7, 3
An answer could look something like. . . (but 1 row for every line of code)
instruction Format Fields 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
loop: bne $s0, $s1, out
Coding Section
Milestone 2 (12 marks)
Remember to comment your code and add student information and
name at the top
Using your first assignment code convert the following label sections to functions:
Please note: assume the user will input the correct operations and numbers you do not need to consider incorrect input.
• readin: section of the code that reads in multiple inputs for example “2 + 3 + 5 – 7 + 1”
• addition: section of the code that adds the following integers in from the input. You will need to use an array to store the numbers to add and keep the result
• subtraction: section of the code that subtracts the following integers and keeps track of the result
To be a function in MIPS the marker will be looking for the following instructions:
• jal
• jr $ra
• storing/using $fp or $sp registers
Bonus (3 marks)
In math you can implement recursive functions like square root or power Given mul is an instruction for multiplying in MIPS, write a function that is recursive that calculates the power. This does not need to work with a string of input, can be a single operation done. Please make sure your user prompt allows the user to know how to use this calculation.
2