Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Translate the C program you wrote to do division in constant time into an assembly program called divAssembly.s. 1. The label for the dividend is

Translate the C program you wrote to do division in constant time into an assembly program called divAssembly.s. 1. The label for the dividend is dividend 1. 4 bytes of space should be made for the dividend 2. The label for the divisor is divisor 1. 4 bytes of space should be made for the divisor 3. Place the quotient in EAX 4. Place the remainder in EDX 5. Don't forget that if you want to shift by a variable amount the shift amount must be placed in CL. Your assembly code won't work if you try to place it in any other register. 6. AFTER the last line of code that you wish to be executed in your program please place the label done. 1. Make sure that there is an instruction after the done line and a new line after that instruction. If you don't your output won't match mine.S 7. IT IS OF VITAL IMPORTANCE THAT YOU NAME YOUR LABELS AS SPECIFIED AND MAKE THE APPROPRIATE AMOUNT OF SPACE FOR EACH VARIABLE! I will be using gdb to test your code and if your labels do not match then the tests will fail. You must also make sure to include the done label AFTER the last line of code you want executed in your program so that I know where to set break points

#include #include

void divide(unsigned int n, unsigned int d, int * q, int * r) { *r = d > n ? n : 0; *q = 0;

if (d == 0 || d > n) return;

for (int i = 15; i >= 0; i--) { if ((d << i) <= n) { *q += (1 << i); n -= (d << i); } } *r = n; }

int main(int argc, char *argv[]) { if (argc < 3) { printf("Usage: ./a.out "); return -1; } int n = atoi(argv[1]), d = atoi(argv[2]); int r = 0, q = 0; divide(n, d, &q, &r); printf("%d / %d = %d R %d ", n, d, q, r); return 0; }

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

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions

Question

Is the book value of inventory on hand a relevant cost? Why?

Answered: 1 week ago

Question

please try to give correct answer 1 0 3 .

Answered: 1 week ago