Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming assignment 0 Using the provided framework .asm file (divu-student.asm, linked via canvas modules) and the MARS MIPS simulator (linked under support documentation), you will

Programming assignment 0

Using the provided framework .asm file (divu-student.asm, linked via canvas modules) and the MARS MIPS simulator (linked under support documentation), 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.

Use the provided slides in the week 5 deck on how to perform unsigned binary division as a guide to implementing your solution. You are free to consult any third party reference on how to perform general binary unsigned division, but you must write (and provide comments for) your own MIPS code solution within the provided framework.

Your code must work within MARS. Links to the MARS documentation and a link to the MARS JAR file itself are available in the Supporting Documentation module. The provided framework will print the results of both the DIVU instruction and your emulated DIVU behavior to the MARS console, so you can directly check if your solution works.

To turn in:

1 File: Your modified divu-student.asm : Please read the comments within the file for what you are requiredto modify and what you are forbidden from modifying in the framework code.

This assignment is not intended to be particularly difficult (a fairly direct translation of the flowchart from the slides into MIPS instructions is an efficient solution, and the recitation on Friday will cover one way to emulate a 64-bit register with 32-bit registers) -- it is, however, intended to force you to use the MARS simulator and write some MIPS assembly code. Please consider starting on this assignment early enough to encounter any issues that you have in using the tools in time to receive assistance.

THE PROVIDED FILE IS BELOW (divu-student.asm):

.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 987654321 # 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

PLEASE HELP WITH THIS QUESTION!

I WILL DEFINITELY RATE!

PLEASE CODE IN .asm FILE, WHICH I THINK IS MIPS ASSEMBLY LANGUAGE!

THANK YOU!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions