Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following programs in Intel assembler. Upload just your cpp source cod

ID: 3784039 • Letter: W

Question

Write the following programs in Intel assembler. Upload just your cpp source code to Blackboard. 1. Write a program that will calculate the log base 2 of an integer. The log base 2 can be easily calculated by counting the number of times you have to shift a number to the right before it is one. include using namespace std int main (int arg n, char argv int number log; cout Enter a number cin number, asm Calculate the log2 of number and store the result in log cout The logarithm is log endl; return 0; 1. Write a program to compute random numbers. If you start with a seed of 1, the 10,000th random value should be 1043618065. Note that the multiplication will often result in a product that is longer than 32 bits.

Explanation / Answer

first program:

#include <iostream>
using namespace std;

int main(int argn,char *argv[])
{
int number,log=0;
cout << "Enter a number >";
cin >> number;
  
/*int count =0;
while(number != 1)
{
number >>=1;
count++;
}
log = count;
*/
  
_asm{
mov ax,number
mov bx,log
  
jmp loop1 ; Jump to condition first
cloop1 add bx,1 ; Execute the content of the loop
sarw $1,bx
loop1 cmp ax,1 ; Check the condition
je cloop1 ; Jump to content of the loop if met
}
cout << "The logarithm is " << log << endl;
return 0;
}

second program:

#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */

int main ()
{
printf ("First number: %d ", rand());
srand (time(NULL)); //set seed value as timestamp in this case our random number will not repeat.
printf ("Random number: %d ", rand());
srand (1); //set the seed value to 1.
printf ("Again the first number: %d ", rand());
  

/* We can long long integer to store big integer multiplication result
**still you getting bigger number then multiplication should be done with
**the help of string.
*/
printf("%lld ",rand()*rand());

return 0;
}