Question: I need help with this: you will implement the body of a function, in MIPS, that provides the same functionality as the DIVU instruction, i.e.

I need help with this: you will implement the body of a function, in MIPS, that provides the same functionality as the DIVU instruction, i.e. computing both the quotient and remainder for unsigned integer division, without using the DIVU instruction itself. The code is the following.

.data divisor: .word 7 # Keep this as 7 when you turn it in; you are, however, encouraged to experiment with other values during testing to make sure your code works ########################### dividend: .word 97067098 # REPLACE THIS WITH YOUR 9-DIGIT PSU ID ########################### spacestring: .asciiz " " endl: .asciiz " "

.text ######################## # Execution begins here la $s0, dividend # get address of dividend lw $s0, 0($s0) # load dividend - keep in s0 to preserve across print calls la $s1, divisor # get address of divisor lw $s1, 0($s1) # load divisor - keep in s1 to preserve across print calls divu $s0, $s1 # do integer division mfhi $a1 # remainder mflo $a0 # quotient jal printDivuResults # print the results to console so that you know what your code is intended to produce addu $a0, $0, $s0 # restore dividend in $a0 after function call addu $a1, $0, $s1 # restore divisor in %a1 after function call ### jal softwareEmulatedDIVU # YOUR CODE INVOKED HERE ### addu $a0, $0, $v0 # quotient in $a0 addu $a1, $0, $v1 # remainder in $a1 jal printDivuResults # print results of your software emulation of DIVU addi $v0, $0, 10 # code for exit syscall syscall # EXIT # Execution ends here ########################

### # Prints quotient and remainder to MARS console ### printDivuResults: # Expects quotient in $a0, remainder in $a1 addi $v0, $0, 1 # printInt syscall # print quotient la $a0, spacestring addi $v0, $0, 4 # printStr syscall # print space addi $v0, $0, 1 # printInt add $a0, $0, $a1 syscall # print remainder la $a0, endl addi $v0, $0, 4 # printStr syscall # print space jr $ra

### # Emulation of DIVU in software without the use of dedicated division hardware ### softwareEmulatedDIVU: # Expects dividend in $a0, divisor in $a1 - produces quotient in $v0, remainder in $v1 beq $a1, $0, sedEXIT # if divide by zero, immediately return (garbage) contents of $v0, $v1 else... #################################################### # 0. A) You cannot use the DIV/DIVU instruction, FP instructions, or the HI|LO register pair # B) You cannot change any assembly outside of i) this code region, ii) replacing the dividend with your 9-digit PSU ID, iii) during testing, replacing the divsor with other values # C) This is an individual assignment # D) You must provide a comment for every line of your assembly code # 1. Your solution must work for all (divisor, dividend) pairs where the divisor is not zero. Your output must match the DIVU output. # Fortunately, A) grammar-school long division satisfies this property # Furthermore, B) the slides provide a flow-chart at an appropriate, bitwise, level # However, the slides use a 64bit shift-register, so you'll have to figure out how to achieve the same effect with 32-bit MIPS registers # 2. Total dynamic instruction count must be upper-bounded by a constant, i.e. cannot grow as a function of dividend/divisor value # To be clear: dynamic instruction count may vary, as a function of input, but must be worst-case bounded proportional to the number # of bits of output generated, not input values # If the instruction count tool says that you're executing more than 1000 dynamic instructions, you're probably not on the right track # 3. A sufficient solution can be achieved in less than 16-20 static instructions - if you're using more than 25 instructions, # your're probably making it MUCH more complex than it needs to be #################################################### ### # YOUR CODE GOES HERE. ### sedEXIT: # softwareEmulatedDIVU exit jr $ra

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!