SECTION II - BINARY CODED DECIMAL NUMBER SYSTEM IN 8051

SECTION II - BINARY CODED DECIMAL NUMBER SYSTEM IN 8051:

BCD Binary Coded Decimal number is used to represent the digital 0 to 9 for number, not binary or hex numbers. Binary representation of 0 to 9 is called BCD. In computer language there are two terms used for BCD numbers. One is unpacked BCD number and the other is packed BCD numbers.

Binary Coded Decimal Numbers [BCD] Code:

DIGITBINARY CODED DECIMAL NUMBER [BCD]
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
  • Unpacked Binary Coded Decimal [BCD] Number:

The lower 4 bits of the number represent the BCD number. The higher bits are zero '0'. e.g "0000 0001", "0000 0010", "0000 0011", "0000 0100", "0000 0101", "0000 0110", "0000 0111", "0000 1000", and "0000 1001" are unpacked binary coded decimal number for 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. So only 1 byte of memory is required for unpacked BCD numbers or an 8 bit register to contain it.

  • Packed Binary Coded Decimal [BCD] Number:

In packed BCD numbers, both the lower and higher 4 bits are used. A single byte has two BCD numbers, one in the lower nibble 4 bits, and one in the upper 4 bits. e.g "0101 1010", is a packed BCD for 5AH. One byte of memory is required to store the packed BCD operands. The packed BCD is twice more efficient as compared to unpacked BCD data.

When adding two BCD numbers, the result must be a BCD number. If after adding two BCD numbers, the result is not BCD number, then it must be corrected by adding the number 6.If the lower bit is need to be corrected then 06 must be added in the lower bits, and if upper bits need to be corrected then 60 must be added to the upper bits. After adding these two digits below, the result is no longer BCD

MOV A, #15H
ADD A, #25H

Adding these two numbers above, the result is 0011 1010 or 3AH in hex. This is not BCD number. The BCD number can only have digits mentioned below: 

"0000", "0010", "0011", "0100", "0101", "0110", "0111", "1000", and "1001"

Adding two BCD number must give a BCD result. The result should have been 15H+25H=40H. This problem is solved by adding 6 to the lower digit 3AH+06H=40H. The same problem can occur in the upper digit. Again to solve this problem, 6 must be added to the upper digit. e.g 52H+87H=D9H or 0101 0010+1000 0111=1101 1001. So adding 6 to the upper digit D9H+60H=139H

MOV A, #52H or 0101 0010
ADD A, #87H or 1000 0111

 

More From Iamtechnical.com

Advertisement: