Question

In: Computer Science

Part (c): An implementation of division You are familiar with integer division operations. In some processors...

Part (c): An implementation of division

You are familiar with integer division operations. In some processors there is no

division instruction. One way to implement division is via repeated subtractions.

NB: This is integer division, NOT floating point division.

For example, consider the expression M / N where M = 370 and N = 120 . If we

repeatedly subtract until we have a value less than N , then the number of times we

do the subtraction is the result. Ie:

● 370 – 120 => 250 (subtraction #1)

● 250 – 120 => 130 (subtraction #2)

● 130 – 120 => 10 (subtraction #3)

When we have the result 10 , we have performed 3 subtractions. Therefore, 370 /

120 = 3

Your task for part (a) is to complete the code in division.asm that has been

provided for you. In that file there are some comments giving several simplifying

assumptions.

For example, the value M will always be a positive two’s-complement number; the

value N will always be a two’s complement positive number less than 128. For

greater certainty, N will never be 0 . Your code will not be tested with inputs that do

not meet these requirements.

Some test cases are provided to you.

# Compute M / N, where M must be in $8, N must be in $9,
# and M / N must be in $15.
# N will never be 0


.text
start:
        lw $8, testcase3_M
        lw $9, testcase3_N

# STUDENTS MAY MODIFY CODE BELOW
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
        
        nop
        addi $15, $0, -10

# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# STUDENTS MAY MODIFY CODE ABOVE

exit:
        add $2, $0, 10
        syscall
                

.data

# testcase1: 370 / 120 = 3
#
testcase1_M:
        .word   370
testcase1_N:
        .word   120
        
# testcase2: 24156 / 77 = 313
#
testcase2_M:
        .word   24156
testcase2_N:
        .word   77
        
# testcase3: 33 / 120 = 0
#
testcase3_M:
        .word   33
testcase3_N:
        .word   120

Solutions

Expert Solution

Greetings!!

Code:

.data

prompt1: .asciiz "Please enter Divident"

prompt2: .asciiz "Please enter Divisor"

output: .asciiz "Quotient = "

.text

#display prompt1

la $a0,prompt1           #load the address of prompt1 message

li $v0,4                        #parameter for syscall for display string

syscall                         #display

#read divident

li $v0,5                        #parameter for syscall for read divident

syscall                         #read

move $t0,$v0              #store dividend in t0

#display prompt2

la $a0,prompt2           #load the address of prompt2 message

li $v0,4                        #parameter for syscall for display string

syscall                         #display

#read divisor

li $v0,5                        #parameter for syscall for read divisor

syscall                         #read

move $t1,$v0              #store divisor in t1

#multiplication

loop:

blt $t0,$t1,end             #if the divisor is less than dividend then go to end

sub $t0,$t0,$t1            #otherwise subtract divisor from the dividend and update divident

addi $t2,$t2,1              #increment the quotient value after one subtraction

j loop                           #repeat

end:

#display output          

la $a0,output               #load the address of the output message

li $v0,4                        #parameter for syscall for display output message

syscall                         #display

#display quotient

move $a0,$t2              #load the quotient into the register a0 for display

li $v0,1                        #parameter for display the quotient

syscall                         #display

#standard termination

li $v0,10                      #parameter for syscall for termination

syscall                         #stop execution

Output screenshots:

Testcase 1:

Testcase 2:

Testcase 3:

Hope this helps

Thank You


Related Solutions

As part of your final project for this course, you researched different types of processors and...
As part of your final project for this course, you researched different types of processors and instruction sets. In addition, you created your own computer architecture including processor architecture, memory structure and algorithms, and an instruction set. You wrote a final report explaining your computer architecture and programming language characteristics and parameters. The project is an opportunity for you to synthesize the concepts you are learning in this course. Up to this point in the course, you communicated within your...
The C++ question: This part of the assignment will give you a chance to perform some...
The C++ question: This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence of tasks that are only loosely related to each other. Start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one....
prepare a quick analysis of a country you are familiar with, discussing some of the factors...
prepare a quick analysis of a country you are familiar with, discussing some of the factors affecting an accounting system of the country: Legal system Providers of financing Taxation Inflation Political and economic ties Culture
Choose a company with which you are familiar. what are some of the ways in which...
Choose a company with which you are familiar. what are some of the ways in which it uses technology to leverage its human capital?. Please cite at least one reference to support your finding.
Choose a company with which you are familiar. What are some of the ways in which...
Choose a company with which you are familiar. What are some of the ways in which it uses technology to leverage its human capital?
Provide some examples of different types of waste in an organization with which you are familiar....
Provide some examples of different types of waste in an organization with which you are familiar. How do you minimize or eliminate it?
Describe an intersection that you are familiar with and describe some characteristic using the terms described...
Describe an intersection that you are familiar with and describe some characteristic using the terms described in this module on how improvements might be made?
Pick a company you are familiar with. Can you identify some of its core competencies? Dont...
Pick a company you are familiar with. Can you identify some of its core competencies? Dont copy paste from the websites. Please answer in more than 350 words and only in word format no images. Please answer all the questions asked. Explain some background of the company and then explain its core competencies. Subject: Management of Technological Innovation Thanks
In this assignment you need to spend some time becoming familiar with the job description. Once...
In this assignment you need to spend some time becoming familiar with the job description. Once you have become familiar with it, you need to evaluate the job using the job evaluation instrument included with this assignment. Based on the job description and job evaluation instrument, you need to select the level in the instrument that most closely matches what is in the job description. Furthermore, if it is unclear what the best match is, you need to indicate this...
Part Two: Download VendingChange.java (above). Run it and become familiar with the output. Essentially, you need...
Part Two: Download VendingChange.java (above). Run it and become familiar with the output. Essentially, you need to create a user friendly GUI app using the code parameters of VendingChange. Turn VendingChange.java into a GUI app. 1) Your program must display the input dialog. 2) You must check that the data entered by the user follows the required input. If not, your program must display an error dialog and exit. 3) If the input is valid, then your program must display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT