Write a program that will calculate the log base 2 of an int
Solution
Answer ) Below is the asemmbly program for calculating the log 2 base of binary integer if you have decimal integer then convert it first to binary integer then do calculation.
steps)
1)First we will push th integer 1024 to analyze using following instruction
2)Do bsr(bit scanning reverse) using the following instruction
3)Then take the zeroth index using the following instruction
4)Then save the previous result into stack using the following instruction
5)Then load the previous result into FPU Stack using the following instruction
6)Then load log10(2) to FPU stack using the following instruction
7)Do the multiplecation of st(0) and st(1) and store the calculation result into st(0) using the following instruction
8)Then set the control word of FPU to round up change from default using the following instruction
9)Saving the old control word of FPU using the following instruction
10)Then stroe the control word of FPU into %ax using the following instruction
11)Then we got to remove everythng else using the following instruction
12)Then we have to set the proper bit to 1 using the following instruction
13)Then get the value back in memory using the following instruction
14)Now we will set the control word to proper value using the following instruction
15) Then we will do rounding up on st(0) using the following instruction
16) Then restore the orignal control word of using the following instruction
17)Then we will load the final result to stack using the following instruction
18)Then we will set the returnvalue to our result using the following instruction
19)leave
20)ret
