1.Find the CY and AC flags for each of the following:
(a)MOV A, #3FHCY=0 No carry out from D7
ADD A, #45HAC=1 carry from D3 to D4
00111111
+01000101
10000100
(b)MOV A, #99HCY=0 No carry out from D7
ADD A, #58HAC=1 carry from D3 to D4
10011001
+01011000
11110001
(c)MOV A, #0FFHCY=1
SETB CAC=0
ADDC A, #00
SETB C-> CY=1
11111111
+CY 1
100000000
+00000000
100000000
(d)MOV A, #OFFHCY=1
ADD A, #1AC=1
11111111
+ 1
100000000
(e)MOV A, #OFEHCY=1
SETB CAC=1
ADDC A, #01
11111110
+ 1
11111111
+ 1
100000000
(f)CLR CCY=1
MOV A, #0FFHAC=1
ADDC A, #01
ADDC A, #0
11111111
+00000001
100000000
+00000000
100000000
2. Write a program to add all the digits of your ID number and save the result in R3. The result must be in BCD.
3. Write a program to add the following numbers and save the result in R2, R3. The data is stored in on-chip ROM. ORG 250H MYDATA: DB 53, 94, 56, 92, 74, 65, 43, 23, 83
4. Modify Problem 3 to make the result in BCD.
6. State the steps that the SUBB instruction will go through for each of the following:
1. Take the 2’s complement of the subtrahend
2. Add it to the minuend
3. Invert the carry
(a) 23H-12H
23H -> 00100011 00100011
12H -> 00010010 – 2’s complement+11101110
100010001
Step 3: CY=1 -> CF=0 Positive number 11H
(b) 43H-53H
43H -> 01000011 01000011
53H -> 01010011 – 2’s complement+10101101 11110000
Step 3: CY=0 -> CF=1 Negative number -F0H
(c) 99-99
99 -> 10011001 10011001
99 -> 10011001 – 2’s complement+01100111
100000000
Step 3: CY=1 -> CF=0 Positive 0
7. For Problem 6, write a program to perform each operation.
8. True or False. The “DA A” instruction works on register A and it must be used after the ADD and ADDC instructions. TRUE
9. Write a program to add 897F9AH to 34BC48H and save the result in RAM memory locations starting at 40H.
10. Write a program to subtract 197F9AH to 34BC48H and save the result in RAM memory locations starting at 40H.
11. Write a program to add 197795H to 344548H and save the BCD result in RAM memory locations starting at 40H.
12. Show how to perform 77 x 34 in the 8051.
13. Show how to perform 77 ÷ 3 in the 8051.
16. show how the following are represented by the assembler:
a. 23 11101001
b. +12 00001100
c. 28 11100100
d. +6FH 01101111
e. 128 10000000
f. +127 011111111
18. Write a program for each of the following and indicate the status of the OV flag for each. a. (+15) + (-12) b. (-123) + (-127) c. (+25H) + (+34H) d. (-127) + (+127)
19. explain the difference between the CY and OV flags and where each one is used. The CY is when there is a carry bit from D7. The OV is set when either there is a carry from D6 to D7 OR a carry out of D7. If both are carried then it is a CY and OC is 0.
20. Explain when the OV flag is raised.