Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

assembly language question please help me the code, thanks! 3. [9 marks] The Root of the Problem In this question, you number. You will write

assembly language question please help me the code, thanks!

image text in transcribedimage text in transcribed

3. [9 marks] The Root of the Problem In this question, you number. You will write sqrt within the file sqrt.s (part of the care package) 1 will implement a subroutine, sqrt, that computes the integ er square root of a The Specification: . The register %edi will contain the argument x. It is an unsigned 32-bit quantity The subroutine sqrt will compute the integer square root of the parameter x. Mathematically, sqrt (x) = IVEJ, where the floor function ly] computes the largest integer that is less than or equal to y. For example, sqrt (5) 2, sqrt (16)- 4 and sqrt (24)- 4 . The register %eax will carry the return value, a 32-bit unsigned quantity . You may only use registers %rax, %rcx, %rdx, %rsi, %rdi, %r8, %r9, %r10 and %r11 as scratch registers. No other memory is allowed, including any of the other registers, or any external memory Your code may not use any of the x86-64 division instructions Your code may not use any of the x86-64 square root instructions, or any of the other floating point arithmetic The Algorithm: Your program wl build the result, one bit at a time, from the most significant bit to the least significant result x then: change the kth bit of result back to 0 return result For example, say x was 2025. Then in the last 8 loops, the result becomes: result fore test result after test k be 7 1000 0000 0000 0000 6 0100 0000 0000 0000 5 0010 0000 0010 0000 4 0011 0000 0010 0000 3 0010 1000 0010 1000 2 0010 1100 0010 1100 1 0010 1110 0010 1100 0 0010 1101 0010 1101 You will submit: (a) 7 marks] an electronic copy of your sqrt.s assembly source. This code will be tested for correct- (b) 2 marks] a hard copy of your sqrt.s assembly source. Your source should be well documented ness using the same mainline routine, but possibly with different inputs with high-level comments, so that any other programmer could read and understand your code This algorithm is well known. Include the common name of this algorithm among your high-level comments (c) [2 BONUS marks] an enhanced version of your work in part (a), except that sqrtrd(x) returns vx, rounded to the nearest integer. Place your source in the file sqrtrd.s. Some Hints: . You may need to use some of the bitwise operators presented on Monday, January 21. The debugger gdb has been enabled for sqrt.s. (Yes, it works for assembly source too.) - You can do list, break, continue and print, as before. After a breakpoint, use step to run one instruction at a time. To print the value of a register, name the register with a dollar sign prefix. E.g., to print the value of rcx, use print $rcx. - Because of the bitwise operations you wil be performing, hex format may be more useful than decimal in some circumstances. E.g., print /x Srcx. If you want the state of all registers in one shot, type info registers. 3. [9 marks] The Root of the Problem In this question, you number. You will write sqrt within the file sqrt.s (part of the care package) 1 will implement a subroutine, sqrt, that computes the integ er square root of a The Specification: . The register %edi will contain the argument x. It is an unsigned 32-bit quantity The subroutine sqrt will compute the integer square root of the parameter x. Mathematically, sqrt (x) = IVEJ, where the floor function ly] computes the largest integer that is less than or equal to y. For example, sqrt (5) 2, sqrt (16)- 4 and sqrt (24)- 4 . The register %eax will carry the return value, a 32-bit unsigned quantity . You may only use registers %rax, %rcx, %rdx, %rsi, %rdi, %r8, %r9, %r10 and %r11 as scratch registers. No other memory is allowed, including any of the other registers, or any external memory Your code may not use any of the x86-64 division instructions Your code may not use any of the x86-64 square root instructions, or any of the other floating point arithmetic The Algorithm: Your program wl build the result, one bit at a time, from the most significant bit to the least significant result x then: change the kth bit of result back to 0 return result For example, say x was 2025. Then in the last 8 loops, the result becomes: result fore test result after test k be 7 1000 0000 0000 0000 6 0100 0000 0000 0000 5 0010 0000 0010 0000 4 0011 0000 0010 0000 3 0010 1000 0010 1000 2 0010 1100 0010 1100 1 0010 1110 0010 1100 0 0010 1101 0010 1101 You will submit: (a) 7 marks] an electronic copy of your sqrt.s assembly source. This code will be tested for correct- (b) 2 marks] a hard copy of your sqrt.s assembly source. Your source should be well documented ness using the same mainline routine, but possibly with different inputs with high-level comments, so that any other programmer could read and understand your code This algorithm is well known. Include the common name of this algorithm among your high-level comments (c) [2 BONUS marks] an enhanced version of your work in part (a), except that sqrtrd(x) returns vx, rounded to the nearest integer. Place your source in the file sqrtrd.s. Some Hints: . You may need to use some of the bitwise operators presented on Monday, January 21. The debugger gdb has been enabled for sqrt.s. (Yes, it works for assembly source too.) - You can do list, break, continue and print, as before. After a breakpoint, use step to run one instruction at a time. To print the value of a register, name the register with a dollar sign prefix. E.g., to print the value of rcx, use print $rcx. - Because of the bitwise operations you wil be performing, hex format may be more useful than decimal in some circumstances. E.g., print /x Srcx. If you want the state of all registers in one shot, type info registers

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions

Question

Do not pay him, wait until I come

Answered: 1 week ago

Question

a neglect of quality in relationship to international competitors;

Answered: 1 week ago