chapter 6 arithmetic instructions and programs
DESCRIPTION
Chapter 6 Arithmetic Instructions and Programs. Outlines. Range of numbers in 8051 unsigned data Addition & subtraction instructions for unsigned data BCD system of data representation Packed and unpacked BCD data Addition & subtraction on BCD data Range of numbers in 8051 signed data - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/1.jpg)
2002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors 11
Suranaree UniversitySuranaree University
Of TechnologyOf Technologyมทสมทส
2002 Anant Oonsivilai2002 Anant Oonsivilai
Chapter 6Chapter 6Arithmetic Instructions Arithmetic Instructions
and Programsand Programs
![Page 2: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/2.jpg)
222002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
OutlinesOutlines
Range of numbers in 8051 unsigned dataRange of numbers in 8051 unsigned dataAddition & subtraction instructions for unsigned Addition & subtraction instructions for unsigned datadataBCD system of data representationBCD system of data representationPacked and unpacked BCD dataPacked and unpacked BCD dataAddition & subtraction on BCD dataAddition & subtraction on BCD dataRange of numbers in 8051 signed dataRange of numbers in 8051 signed dataSigned data arithmetic instructionsSigned data arithmetic instructionsCarry & overflow problems & correctionsCarry & overflow problems & corrections
![Page 3: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/3.jpg)
332002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Addition of Unsigned NumbersAddition of Unsigned Numbers
ADDADD A, sourceA, source ; A = A + ; A = A + sourcesource
![Page 4: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/4.jpg)
442002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
![Page 5: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/5.jpg)
552002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Addition of Individual BytesAddition of Individual Bytes
![Page 6: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/6.jpg)
662002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ADDC & Addition of 16-bit NumbersADDC & Addition of 16-bit Numbers
13C E73B 8D78 74
+
![Page 7: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/7.jpg)
772002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
BCD Number SystemBCD Number System
Unpacked BCD: 1 byteUnpacked BCD: 1 byte
Packed BCD: 4 bitsPacked BCD: 4 bits
![Page 8: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/8.jpg)
882002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Adding BCD Numbers & DA InstructionAdding BCD Numbers & DA Instruction
MOVMOV A,#17HA,#17H
ADDADD A,#28HA,#28H
MOVMOV A,#47HA,#47H ;A=47H first BCD operand;A=47H first BCD operandMOVMOV B,#25HB,#25H ;B=25 second BCD operand;B=25 second BCD operand
ADDADD A,BA,B ;hex (binary) addition (A=6CH);hex (binary) addition (A=6CH)
DADA AA ;adjust for BCD addition(A=72H);adjust for BCD addition(A=72H)
HEXHEX BCDBCD
2929 0010 10010010 1001
++ 1818 +0001 1000 +0001 1000
4141 0100 00010100 0001 AC=1AC=1
++ 6 6 + 0110 + 0110
4747 0100 01110100 0111
![Page 9: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/9.jpg)
992002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 10: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/10.jpg)
10102002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Subtraction of Unsigned NumbersSubtraction of Unsigned Numbers
SUBBSUBB A, sourceA, source ; A = A – source – CY; A = A – source – CY
SUBB when CY = 0SUBB when CY = 0 Take 2’s complement of subtracted (source)Take 2’s complement of subtracted (source) Add it to minuendAdd it to minuend Invert carryInvert carry
![Page 11: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/11.jpg)
11112002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Example (Positive Result)Example (Positive Result)
![Page 12: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/12.jpg)
12122002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Example (Negative Result)Example (Negative Result)
![Page 13: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/13.jpg)
13132002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
SUBB When CY = 1SUBB When CY = 1For multibyte numbersFor multibyte numbers
![Page 14: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/14.jpg)
14142002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Multiplication of Unsigned NumbersMultiplication of Unsigned Numbers
MULMUL ABAB ; A ; A B, place 16-bit result in B and A B, place 16-bit result in B and A
MOVMOV A,#25HA,#25H ;load 25H to reg. A;load 25H to reg. A
MOVMOV B,#65HB,#65H ;load 65H in reg. B;load 65H in reg. B
MULMUL ABAB ;25H * 65H = E99 where;25H * 65H = E99 where
;B = 0EH and A = 99H;B = 0EH and A = 99H
Table 6-1:Unsigned Multiplication Summary (MUL AB)Table 6-1:Unsigned Multiplication Summary (MUL AB)
MultiplicationMultiplication Operand 1Operand 1 Operand 2Operand 2 ResultResult
byte byte bytebyte AA BB A=low byte,A=low byte,
B=high byteB=high byte
![Page 15: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/15.jpg)
15152002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Division of Unsigned NumbersDivision of Unsigned Numbers
DIVDIV ABAB ; divide A by B; divide A by B
MOVMOV A,#95HA,#95H ;load 95 into A;load 95 into A
MOVMOV B,#10HB,#10H ;load 10 into B;load 10 into B
DIVDIV ABAB ;now A = 09 (quotient) and ;now A = 09 (quotient) and
;B = 05 (remainder);B = 05 (remainder)
Table 6-2:Unsigned Division Summary (DIV AB)Table 6-2:Unsigned Division Summary (DIV AB)
DivisionDivision NumeratorNumerator DenominatorDenominator QuotientQuotient RemainderRemainder
byte / bytebyte / byte AA BB AA BB
![Page 16: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/16.jpg)
16162002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Example ( 1 of 2 )Example ( 1 of 2 )
![Page 17: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/17.jpg)
17172002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Example ( 2 of 2 )Example ( 2 of 2 )
![Page 18: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/18.jpg)
18182002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Signed 8-bit OperandsSigned 8-bit Operands
Covert to 2’s complementCovert to 2’s complement Write magnitude of number in 8-bit binary (no Write magnitude of number in 8-bit binary (no
sign)sign) Invert each bitInvert each bit Add 1 to itAdd 1 to it
![Page 19: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/19.jpg)
19192002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 20: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/20.jpg)
20202002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 21: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/21.jpg)
21212002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 22: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/22.jpg)
22222002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Byte-sized Signed Numbers Byte-sized Signed Numbers RangesRanges
DecimalDecimal BinaryBinary HexHex
-128-128 1000 00001000 0000 8080
-127-127 1000 00011000 0001 8181
-126-126 1000 00101000 0010 8282
…….. …………………… ....
-2-2 1111 11101111 1110 FEFE
-1-1 1111 11111111 1111 FFFF
00 0000 00000000 0000 0000
+1+1 0000 00010000 0001 0101
+2+2 0000 00100000 0010 0202
…… …………………… ......
+127+127 0111 11110111 1111 7F7F
![Page 23: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/23.jpg)
23232002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
Overflow in Signed Number Overflow in Signed Number OperationsOperations
![Page 24: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/24.jpg)
24242002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
When Is the OV Flag Set?When Is the OV Flag Set?
Either: there is a carry from D6 to D7 but Either: there is a carry from D6 to D7 but no carry out of D7 (CY = 0)no carry out of D7 (CY = 0)
Or: there is a carry from D7 out (CY = 1) Or: there is a carry from D7 out (CY = 1) but no carry from D6 to D7but no carry from D6 to D7
![Page 25: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/25.jpg)
25252002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 26: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/26.jpg)
26262002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample
![Page 27: Chapter 6 Arithmetic Instructions and Programs](https://reader033.vdocuments.site/reader033/viewer/2022061605/568150af550346895dbeca21/html5/thumbnails/27.jpg)
27272002/4/82002/4/8 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors2002 Anant Oonsivilai2002 Anant Oonsivilai
ExampleExample