I've got this task:
dividePower2
Compute x/2n, for 0 ≤ n ≤ 30. Round toward zero.
- Argument 1:
x- Argument 2:
nExamples:
dividePower2(15,1) = 7dividePower2(-33,4) = -2
This is what I've got so far but I don't know if I'm heading in the right direction (AT&T syntax required):
.global dividePower2
dividePower2:
sar $2, %esi
ret
You need to use the IEEE standard of floating numbers in Computing.It will take up more memory but I dont see any other way.
Remember that any floating number can be written as :
s|exp bits|fraction bits
Let n1=x = s_x|exp bits_x|fraction bits_x
and n2=2^n 0|b(n+127)|0
n1/n2 will be simply equal to s_x|exp bits_x-b(n+127)|fraction bits_x
You will need 2 32-bit registers to store the divident and the divisor and 1 32-bit register for the result.