2. Write a program that will calculate the log base 2 of an integer using the In
ID: 3787067 • Letter: 2
Question
2. Write a program that will calculate the log base 2 of an integer using the Intel BSR instruction. The BSR instruction has the format BSR register, data The instruction finds the position of the leftmost 1 bit in the second operand, which can be a memory location or a register. This result is stored in the first register. #include kiostream> using namespace std; int main (int argn char argv [1) int number log cout Enter a number cin number; asm t Calculate the log2 of number and store the result in log cout The logarithm is log endl; return 0;Explanation / Answer
#include <iostream>
using namespace std;
int main(int argn, char *argv[]) {
int number, log;
cout<<"Enter a number";
cin>>number;
_asm {
CALL #__gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::log<int>(int)
MOV R12, R8
MOV R13, R9
MOV R14, R10
MOV R15, R11
MOV #2, R12
CALL #__gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::log<int>(int)
MOV R12, R8
MOV R13, R9
MOV R14, R10
MOV R15, R11
BSR $log R15
}
cout<<"The logarithm is"<<log<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.