Professional Documents
Culture Documents
Chapter 6
Spring'17 TW 8051
Hou 1
成功大學工程科學系
• 6.1Arithmetic Instructions
• 6.2 Signed number concepts and arithmetic
operations
• 6.3 Logic and compare instructions
• 6.4 Rotate instruction and data serialization
• 6.5 BCD, ASCII, and other application programs
Spring'17 TW 8051
Hou 6
成功大學工程科學系
Spring'17 TW 8051
Hou 8
成功大學工程科學系
Spring'17 TW 8051
Hou 10
成功大學工程科學系
Unpacked BCD
• Lower 4 bits represent the BCD number, the rest
of the bits are 0.
• Ex: unpacked BCD of ‘0000 1001” BCD 9
• unpacked BCD of ‘0000 0101’ BCD 5
Packed BCD
• A single byte contains two BCD numbers.
• Ex: packed BCD ‘0101 1001’ is 59H
• Packed BCD is more efficient to store data than
unpacked BCD
• NOTE: There is a problem: after adding packed
BCD numbers, the result is no longer BCD
• EX: MOV A,#17H; 17H + 28H = 3FH
• ADD A,#28H; 3FH is not a BCD
• ; the result should be 45H
• ; in BCD
Spring'17 TW Hou 8051
13
成功大學工程科學系
Packed BCD
• MOV A,#17H; 17H + 28H = 3FH
• ADD A,#28H; 3FH is not a BCD
• ; the result should be 45H ( in BCD)
• ; add 6 to the lower digit: 3FH + 6H = 45H
• ;another example of higher digit:
• ;52H + 87H = D9H (52D + 87D = 139D)
• ; add 6 the the higher digit: D9H + 60H = 139H
• ; decimal adjustment
Spring'17 TW 8051
Hou 16
成功大學工程科學系
Spring'17 TW 8051
Hou 17
成功大學工程科學系
Spring'17 TW 8051
Hou 21
成功大學工程科學系
Spring'17 TW 8051
Hou 23
成功大學工程科學系
Spring'17 TW 8051
Hou 27
成功大學工程科學系
• Positive numbers:
• Negative numbers: 2’s complement of a positive
number.
– Example 6-9,6-10,6-11
Exampl 6-10
Example 6-11
Example 6-12
Spring'17 TW 8051
Hou 33
成功大學工程科學系
Example 6-13
Example 6-14
Example 6-15
Example 6-16
6-2 ends
Spring'17 TW 8051
Hou 42