Question: In x 8 6 - 6 4 assembly language, write the definition of the function modulus that efficiently calculates the modulus of a signed integer

In x86-64 assembly language, write the definition of the function modulus that efficiently calculates the modulus of a signed integer division using only bitwise operations and without using the IDIV instruction? Assume the divisor is a power of 2. Hint1:Foranyintegerxandadivisor2^n,themodulusisequivalenttox&(2^n -1).
Hint2: For signed integers, we have to adjust for negative numbers to get the correct result(-x & (2^n -1).
(You will get partial credit if you at least give an attempt)
The following is a skeleton code of the function modulus in assembly code, modulus.S. Complete the code..
decode:
movl %edi, %eax
andl %esi, %edi
orl %edi, %eax
sall %esi, %eax
ret
3.
.global modulus
# %edi holds v and %esi holds n
movq %edi, %eax # move v to %eax
movq %esi, %ecx # move n to %ecx
# calculate 2^n-1 to get the mask for modulus
# calculate the modulus operation. Put the result into %eax
ret

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