5. Additional Review
• Decimal
1
3 4 +
9 4
1 2 8
1
9 +
9
1 8
• Hexadecimal
0
B 4 +
1 4
C 8
1
F +
F
1 E
1
F F +
0 1
1 0 0
1
F F +
F F
1 F E
28 July 2016 Microprocessor 5
Additional
MSB
One Byte
Answer
6. MCS-51 Additional Operation
• Law of operation with Assembly
– The First operand MUST be Acc
– Every additional operation, the Result will store in
• Carry flag (as Most Significant bit)
• Acc
– Every Additional will effect to Carry flag
28 July 2016 Microprocessor 6
7. Additional Instructions
– Instructions
• ADD A, Rn
• ADD A, #X
• ADD A, Rx
• ADD A, @Ri
• ADDC A, Rn
• ADDC A, #X
• ADDC A, Rx
• ADDC A, @Ri
28 July 2016 Microprocessor 7
8. Sample Additional (Small number)
• A =
+
• R3 =
• ADD A, R3
• C = = Acc
8 C
3 8
C 40
28 July 2016 Microprocessor 8
9. Sample Additional (Big number)
• A =
+
• R3 =
• ADD A, R3
• C = = Acc
A 7
B 3
5 A1
28 July 2016 Microprocessor 9
10. Simple Additional Program
• See Handout Chapter 8
• Example 0:
• Program to summation R0 and R1, then
28 July 2016 Microprocessor 10
11. Sample “16-bits Additional Program”
• “16-bits Additional Program”
– Such as: 1001100110111011+ 99BB+
1101110010111011 DCBB
1 0111011001110110 1 76 76
• Solution:
– Because the word size of MCS-51 is 8-bits, the
diagram able to draw as below.
28 July 2016 Microprocessor 11
12. Sample “16-bits Additional Program”
9 9 B B
D C 6 4
x x x x
R1 R2
28 July 2016 Microprocessor 12
P2 P1
x x
ORG 00H
MOV A, R2
ADD A, P1 ; C, Acc
MOV 12h, A
MOV A, R1
ADDC A, P2 ; C, Acc
MOV 11h, Acc
CLR A
MOV Acc.0, C
MOV 10h, Acc
END
10h 11h 12h
01 76 1F
13. MCS-51 Subtraction Operation
• Law of operation
– Every Subtraction will include Carry flag
– Result will store in Acc
– Result on Carry flag
• “0” on Carry flag represent Positive result in Acc
• “1” on Carry flag represent Negative result in Acc
– Negative number result will be show in a Second
complement format
– Every Subtraction will effect to Carry flag
28 July 2016 Microprocessor 13
14. Subtraction Review
• Decimal
3 4 -
1 2
2 2
5 +
9
- 4
• Hexadecimal
B 4 -
1 4
C 8
1 C -
1 E
F E
28 July 2016 Microprocessor 14
Borrow (C) = 1
FE = 2 Complement of -2
15. Mathematic on Binary System
• Normal
5 -
7
-2
+ 4
2
• Binary System
0 5 -
0 7
F E
+ 0 4
0 2
28 July 2016 Microprocessor 15
FE = 2’n Complement of -2
Borrow (C) = 1
16. Subtraction Instruction
– Instructions
• SUBB A, Rn
• SUBB A, #X
• SUBB A, Rx
• SUBB A, @Ri
• Note: Every Additional will effect to Carry flag
28 July 2016 Microprocessor 16
17. 32 bits Subtraction Program
• _
28 July 2016 Microprocessor 17
9 9 7 A
1 C 9 4
x x x x
11h 12h
21h 22h
9 D B B
D 3 6 4
13h 14h
x x x x
23h 24h
R1 R2 R3 R4
ORG 00H
CLR C
MOV A, R4
SUBB A, 14h
MOV 24h, A
MOV A, R3
SUBB A, 13h
MOV 23h, Acc
MOV A, R2
SUBB A, 12h
MOV 22h, Acc
MOV A, R1
SUBB A, 11h
MOV 21h, Acc
END
18. Test in Assembly Editor and Emulator
28 July 2016 Microprocessor 18
19. Assignment 1
• Chapter 8, Example 2
– Complete the Example 2 then check your code in the
Laboratory
– Check and Sign by Instructor
28 July 2016 Microprocessor 19
20.
21. Homework 2
• Chapter 8,
– Refer to Example 3
– Write diagram and assembly code for MCS-51 to process
“32bits additional program”
– Specify data enter location by yourself.
– Generate Test data by your self (if needed)
– Submit before next class start.
28 July 2016 Microprocessor 21
22. Multiplication Operation
• Only operate by Register Acc and B
• Answer
– Low Byte store in Acc
– High Byte store in B
• Instruction
– MUL AB
28 July 2016 Microprocessor 22
3 E
9 2
x xy y
x
24. Sample Multiplication Operation
16-bits multiplication:
See Handout Chapter 8
Example 4
28 July 2016 Microprocessor 24
3 E
9 2 x
9 29 2
9 29 2
9 29 2
9 29 2
9 29 2 9 29 2
25. Division Operation
• Operate by register Acc and B
– Acc / B
• Answer
– Answer store in Acc
– Fraction store in B
• Instruction
– DIV AB
28 July 2016 Microprocessor 25
3 E0 5
26. Assignment 2
• Perform write program for MCS51 to operate
“16-bits Multiplication”
• Check by Instructor
28 July 2016 Microprocessor 26