EXERCISES

Posted by Atezaz | 6:52 PM | | 0 comments »

1. Write a program to swap every pair of bits in the AX register.

2. Give the value of the AX register and the carry flag after each of the following instructions.

stc

mov ax,

adc ah, cmc

xor ah, al mov cl, 4 shr al, cl rcr ah, cl

3. Write a program to swap the nibbles in each byte of the AX register.

4. Calculate the number of one bits in BX and complement an equal number of least significant bits in AX.
HINT: Use the XOR instruction

5. Write a program to multiply two 32bit numbers and store the answer in a 64bit location.
6. Declare a 32byte buffer containing random data. Consider for this problem that the bits in these 32 bytes are numbered from 0 to 255. Declare another byte that contains the starting bit number. Write a program to copy the byte starting at this starting bit number in the AX register. Be careful that the starting bit number may not be a multiple of 8 and therefore the bits of the desired byte will be split into two bytes.

7. AX contains a number between 0-15. Write code to complement the corresponding bit in BX. For example if AX contains 6; complement the 6th bit of BX.
8. AX contains a non-zero number. Count the number of ones in it and store the result back in AX. Repeat the process on the result (AX) until AX contains one. Calculate in BX the number of iterations it took to

make AX one. For example BX should contain 2 in the following case: AX = 1100 0101 1010 0011 (input – 8 ones)

AX = 0000 0000 0000 1000 (after first iteration – 1 one)

AX = 0000 0000 0000 0001 (after second iteration – 1 one) STOP

0 comments