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

Write an assembly program to test if the MSB in the register a1 is set: If it is

ID: 3821452 • Letter: W

Question

Write an assembly program to test if the MSB in the register a1 is set: If it is set, then divide the content of a1 by 4 using the appropriate shift instruction and exit. Else, if it is not set, then multiply the content of al by 8 using the appropriate shift instruction and exit. When checking a1 MSB, do not change a1 content. Assume that a1 is equal to the signed integer 18h. You need to come up with the appropriate mask to check the MSB. Run your program using the debugger to verify your answers, Submit the following: Lastname1.asm Implement the following expression in assembly language, using 32-bit signed operands: val1 = (val2/val3) * (val4 + val2) - (val4 * 3) Use the appropriate multiplication and division instructions. Use the CBW, CWD, or CDQ instructions when needed. For (val4 * 3), you must use the two operands format. Run your program using the debugger to verify your answers, Submit the following: Lastname2.asm

Explanation / Answer

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int highest_bit_unrolled(long long n);
int highest_bit(long long n);

main(int argc, char **argv)
{
long long n = strtoull(argv[1], NULL, 0);
int b1, b2;
long i;
clock_t start = clock(), mid, end;

for (i = 0; i < 1000000000; i++)
b1 = highest_bit_unrolled(n);

mid = clock();

for (i = 0; i < 1000000000; i++)
b2 = highest_bit(n);

end = clock();

printf("highest bit of 0x%llx/%lld = %d, %d ", n, n, b1, b2);

printf("time1 = %d ", (int) (mid - start));
printf("time2 = %d ", (int) (end - mid));
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote