0% found this document useful (0 votes)
23 views22 pages

Binary Coded Decimal Notable

This document discusses binary coded decimal (BCD) representation and arithmetic. It describes unpacked and packed BCD formats. Unpacked BCD uses one byte per decimal digit, while packed BCD stores two digits in one byte. The document outlines ASCII to BCD conversion and various BCD arithmetic instructions, including addition/subtraction with correction, multiplication/division, and conversions between ASCII and BCD formats. It explains common problems that can occur, such as results greater than 9, and how instructions like DAA, DAS, AAM, and AAD address those problems.

Uploaded by

zaccurate.125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views22 pages

Binary Coded Decimal Notable

This document discusses binary coded decimal (BCD) representation and arithmetic. It describes unpacked and packed BCD formats. Unpacked BCD uses one byte per decimal digit, while packed BCD stores two digits in one byte. The document outlines ASCII to BCD conversion and various BCD arithmetic instructions, including addition/subtraction with correction, multiplication/division, and conversions between ASCII and BCD formats. It explains common problems that can occur, such as results greater than 9, and how instructions like DAA, DAS, AAM, and AAD address those problems.

Uploaded by

zaccurate.125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Binary Coded Decimal

(BCD)
Unpacked BCD

⇒ Lower four bits represent BCD number


⇒ Rest of the bits are 0

Example: 00000101 = 5

00001001 = 9

⇒ Unpacked BCD takes 1 byte or 8 bits to contain an integer


Packed BCD

→ A single byte contains two BCD numbers


→ One in the upper four bits and one in the lower four bits

Example: 10010101 = 95

00111000 = 38

→ Takes one byte to store two numbers

→ BCD is twice as memory efficient as storing ASCII numbers


ASCII to BCD conversion

→ If data is to be in packed or unpacked BCD depends on


instructions to be used

→ Some 80 X 86 instructions require data to be in packed BCD

→ Some 80 X 86 instructions require data to be in unpacked BCD


ASCII to Unpacked BCD conversion

→ To convert ASCII to BCD get rid of the tagged 011

♣Accomplished by ANDing with 00001111


ASCII to packed BCD conversion
Packed BCD to ASCII conversion

→ To convert packed BCD to ASCII

→ Convert to unpacked

→ Tag with 0011 or use 0011000


Packed BCD to ASCII conversion
BCD addition and subtraction

→ BCD addition and correction

→ Adding two BCD numbers must give a BCD result

If not a BCD result add 6 (0110) to the low digit

If problem with upper digit add 6 (0110) to upper digit


Decimal adjust for addition
→ Correct the problem associated with BCD addition
→ Adds 0110 to the lower nibble if needed- otherwise byte if left
alone
→ Destination must be in al
Example
Summary of DAA action
1.If after an ADD or ADC lower nibble>9 or if AF=1 add 0110 to
lower 4 bits
2. If upper nibble>9 or CF=1 add 0110 to upper nibble
This is the reason for the AF flag
BCD subtraction & correction
→ Same problem shows up in subtraction as in addition

→ Use DAS to solve the problem

→ When subtracting single or multibyte put DAS after SUB or SBB

→ Al must be the destination register for DAS to work

→ If after SUB or SBB instruction/lower nibble greater than 9, or if AF= 1 subtract 0110
from lower 4 bits

→ If upper nibble greater than 9 or CF = 1 subtract 0110 from upper nibble

→ DT directive designed specifically for use with BCD

→ Can hold numbers from 0 to 1020~1 (twenty 9’s)


BCD subtraction & correction
Unpacked BCD multiplication and division

→ Two commands

→ Convert the result back to unpacked BCD


Ascii Adjust for
Multiplication
AAM

→If two unpacked BCD numbers are multiplied result can be converted back to BCD by AAM

→Multiplication byte by byte result in HEX

→Use AAM to convert to unpacked BCD


→Tag with 30h to convert to ASCII
ASCII Adjust for Division
AAD
→ Data must be unpacked BCD to work
→ Before dividing the unpacked BCD by another
→ Unpack BCD, Use AAD to convert to HEX.
⇒ Quotient & remainder will both be unpacked BCD

→ With help of AAD result is unpacked BCD

→ Tag with 30h to get ASCII result AAM & AAD work only w/AX
ASCII addition & subtraction

→ ASCII numbers can be used for adding and subtraction the way
they are

→ No need to mask off the tagged 011

→ Use AAA and AAS instructions


Continued
→ If addition result greater than 9
⇒ AAA will correct and pass extra bit to carry & add 1 to AH
Continued
To Be Continued

THE END

You might also like