Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.

Presentation on theme: "Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4."— Presentation transcript:

Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4

Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic BCD: Binary Coded Decimal Packed BCD Arithmetic –BCD Addition –BCD Subtraction Unpacked BCD Arithmetic –ASCII Addition –ASCII Subtracition –BCD Multiplication –BCD Division

Introduction to Computer Engineering by Richard E. Haskell Binary Coded Decimal Code decimal numbers using the binary digits, 0 - 9. That is, 0000 - 1001. Can NOT use the hex digits A - F. For example, the DECIMAL number 3582 would be coded in BCD as 0011 0101 1000 0010 While this looks like the HEX number 3582H in BCD we interpret it as the DECIMAL number 3582.

Introduction to Computer Engineering by Richard E. Haskell BCD Addition Binary 35H 00110101 +47H 01000111 7CH 01111100 Decimal (BCD) 35H 00110101 +47H 01000111 82H 10000010 0000 B0 35 MOV AL,35H ;AL = 35H 0002 04 47 ADD AL,47H ;AL = AL+47H 0004 27 DAA ;Decimal adjust

Introduction to Computer Engineering by Richard E. Haskell BCD Subtraction Binary 52H 01010010 -25H 00100101 2DH 00101101 Decimal (BCD) 52H 01010010 -25H 00100101 27H 00100111 0000 B0 52 MOV AL,52H ;AL = 52H 0002 2C 25 SUB AL,25H ;AL = AL-25H 0004 2F DAS ;Decimal adjust

Introduction to Computer Engineering by Richard E. Haskell ASCII Addition DecimalASCII 9 +6 15 39 +36 01 05 AH AL 0000 B8 39 00 MOV AX,0039H ;AL = 39H 0003 04 36 ADD AL,36H ;AL = AL + 36H 0005 37 AAA ;ASCII adjust

Introduction to Computer Engineering by Richard E. Haskell ASCII Subtraction DecimalASCII 6 -9 7 36 -39 FF 07 AH AL 0000 B8 36 00 MOV AX,0036H ;AL = 36H 0003 2C 39 SUB AL,39H ;AL = AL - 39H 0005 3F AAS ;ASCII adjust Borrow = 1 Carry flag = 1

Introduction to Computer Engineering by Richard E. Haskell BCD Multiplication DecimalASCII 8 x7 56 08 x07 05 06 AH AL 0000 B0 08 MOV AL,08H ;AL = 08H 0002 B3 07 MOV BL,07H ;BL = 07H 0004 F6 E3 MUL BL ;AL = AL x BL 0006 D4 0A AAM ;ASCII adjust Binary(Hex) 08 x07 38

Introduction to Computer Engineering by Richard E. Haskell BCD Division 9 = quotient 6 56 54 2 = remainder Decimal 0000 B0 06 05 MOV AX,0506H ;AX = 0506H 0003 B3 06 MOV BL,06H ;BL = 06H 0005 D5 0A AAD ;Adjust AX for ; BCD div 0007 F6 F3 DIV BL ;divide 9 6 36 32 2 Hex