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?
Imagine you are an administrator at a hospital that is considering the implementation of EHR. Some...
Imagine you are an administrator at a hospital that is considering the implementation of EHR. Some providers are for it while others argue against it. As an administrator, you are obligated to consider ethics concerns as well as appropriate resource allocation. Discuss the ethics concern that you must consider in this situation. Now, think about the investment costs of EHR. Which principles of ethics can you use to defend (or not) the investment required to implement EHR?
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?
In this project, you are required to write the java program “IO.java” to implement integer operations...
In this project, you are required to write the java program “IO.java” to implement integer operations “+”, “−”, “*”. Specifically, your program reads operands from a file named “input.txt” (which will be manually placed under the directory of the program) as strings. Then your program converts strings to integers, and computes the addition, subtraction, and multiplication of the operands. Finally, your program creates a file named “output.txt” (under the directory of the program) and writes the results to the file....
Java program - you are not allowed to use arithmetic operations such as division (/), multiplication,...
Java program - you are not allowed to use arithmetic operations such as division (/), multiplication, or modulo (%) to extract the bits. In this exercise use only logic bit-wise operations. Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you CANNOT use the arithmetic division by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT