BCD Arithmetic Module M 16 5 Section 10
BCD Arithmetic Module M 16. 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 3582 H in BCD we interpret it as the DECIMAL number 3582. Introduction to Computer Engineering by Richard E. Haskell
BCD Addition Binary 35 H +47 H 7 CH 0000 0002 0004 Decimal (BCD) 00110101 010001111100 B 0 35 04 47 27 MOV ADD DAA 35 H +47 H 82 H AL, 35 H AL, 47 H 00110101 01000111 10000010 ; AL = 35 H ; AL = AL+47 H ; Decimal adjust Introduction to Computer Engineering by Richard E. Haskell
BCD Subtraction Binary 52 H -25 H 2 DH 0000 0002 0004 Decimal (BCD) 010100100101 00101101 B 0 52 2 C 25 2 F MOV SUB DAS 52 H -25 H 27 H AL, 52 H AL, 25 H 010100100101 00100111 ; AL = 52 H ; AL = AL-25 H ; Decimal adjust Introduction to Computer Engineering by Richard E. Haskell
ASCII Addition Decimal ASCII 9 +6 15 0000 0003 0005 B 8 39 00 04 36 37 39 +36 01 05 AH AL MOV ADD AAA AX, 0039 H AL, 36 H ; AL = 39 H ; AL = AL + 36 H ; ASCII adjust Introduction to Computer Engineering by Richard E. Haskell
ASCII Subtraction Decimal ASCII 6 -9 Borrow = 1 7 0000 0003 0005 B 8 36 00 2 C 39 3 F 36 -39 FF 07 AH AL MOV SUB AAS AX, 0036 H AL, 39 H Carry flag = 1 ; AL = 36 H ; AL = AL - 39 H ; ASCII adjust Introduction to Computer Engineering by Richard E. Haskell
BCD Multiplication Decimal Binary(Hex) 8 x 7 56 0000 0002 0004 0006 B 0 B 3 F 6 D 4 08 x 07 38 08 07 E 3 0 A MOV MUL AAM AL, 08 H BL, 07 H BL ASCII 08 x 07 05 06 AH AL ; AL = 08 H ; BL = 07 H ; AL = AL x BL ; ASCII adjust Introduction to Computer Engineering by Richard E. Haskell
BCD Division Decimal Hex 9 = quotient 6 56 54 2 = remainder 0000 0003 0005 B 0 06 05 B 3 06 D 5 0 A MOV AAD AX, 0506 H BL, 06 H 0007 F 6 F 3 DIV BL 9 6 36 32 2 ; AX = 0506 H ; BL = 06 H ; Adjust AX ; BCD div ; divide Introduction to Computer Engineering by Richard E. Haskell
- Slides: 9