Question: Task 1 : Binary Integer Long Division The C code below implements a long - division algorithm for binary integers. int division ( int dividend,

Task 1: Binary Integer Long Division
The C code below implements a long-division algorithm for binary integers.
int division(int dividend, int divisor){ int sign =0, quotient =0; // Determine the sign of the result if (dividend <0){ sign =!sign; dividend =-dividend; } if (divisor <0){ sign =!sign; divisor =-divisor; }// We produce a 32-bit result int remainder =0; for (int i =32-1; i >=0; i--){// Intermediate result left shift by 1 remainder <<=1; // Append the next bit in the dividend remainder = remainder |(dividend >> i) & 1; if (remainder >= divisor){ remainder -= divisor; // Append 1 to the corresponding bit in quotient quotient = quotient |1<< i; }} if (sign){ quotient =-quotient; } return quotient; }
Your task is to write equivalent assembly code as follows:
dividend: .word 10 divisor: .word 2.global _start _start: // R0: stores the quotient MOV R0, #0// your code starts here // your code ends here end: B end
Your implementation must:
Load dividend from the label named dividend
Load divisor from a label named divisor
Put the quotient inside R0
You may assume:
The dividend, divisor, and quotient are signed 32-bit integers
The divisor is non-zero
We do not care about the remainder
Testing Instructions
You can find the template task_1.s for task 1. Please directly implement your code in this template and submit. To support automated grading, please carefully note the following requirements:
You must implement your code within the designated area, i.e., between // your code starts here and // your code ends here. You are allowed to write anything you see fit within this area, including additional subroutines. Anything written outside the area will be removed by the autograder.
Your submission must not modify the existing instructions and labels in the template.
Your submission must use the same filename (task_1.s) as the template.
You need to come up with your own test cases to explore the functionality of your code. The tester will automatically change the dividend and divisor numbers in your code for grading.

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 Programming Questions!