Chapter 3 JUMP, LOOP and CALL Instructions
description
Transcript of Chapter 3 JUMP, LOOP and CALL Instructions
![Page 1: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/1.jpg)
REF::NATIONAL TAIWANOCEAN UNIVERSITYREF::NATIONAL TAIWANOCEAN UNIVERSITY國立台灣海洋大學國立台灣海洋大學
University Of Engineering And Technology TaxilaUniversity Of Engineering And Technology Taxila
Chapter 3Chapter 3JUMP, LOOP and CALL JUMP, LOOP and CALL InstructionsInstructions
![Page 2: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/2.jpg)
OutlinesOutlines Loop instructionsLoop instructions Conditional jump instructionsConditional jump instructions Conditions determining conditional jumpConditions determining conditional jump Unconditional long & short jumpsUnconditional long & short jumps Calculate target addresses for jumpsCalculate target addresses for jumps SubroutinesSubroutines Using stack in subroutinesUsing stack in subroutines Crystal frequency vs. machine cycleCrystal frequency vs. machine cycle Code programs to generate time delayCode programs to generate time delay
![Page 3: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/3.jpg)
LoopingLooping
![Page 4: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/4.jpg)
Loop inside a Loop (Nested Loop)Loop inside a Loop (Nested Loop)
![Page 5: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/5.jpg)
8051 Conditional Jump Instructions8051 Conditional Jump Instructions
![Page 6: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/6.jpg)
Conditional Jump ExampleConditional Jump Example
![Page 7: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/7.jpg)
Conditional Jump ExampleConditional Jump Example
![Page 8: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/8.jpg)
Unconditional Jump InstructionsUnconditional Jump Instructions All conditional jumps are short jumpsAll conditional jumps are short jumps
– Target address within -128 to +127 of PCTarget address within -128 to +127 of PC LJMPLJMP (long jump): 3-byte instruction (long jump): 3-byte instruction
– 2-byte target address: 0000 to FFFFH2-byte target address: 0000 to FFFFH– Original 8051 has only 4KB on-chip ROMOriginal 8051 has only 4KB on-chip ROM
SJMPSJMP (short jump): 2-byte instruction (short jump): 2-byte instruction– 1-byte relative address: -128 to +1271-byte relative address: -128 to +127
![Page 9: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/9.jpg)
Call InstructionsCall Instructions LCALLLCALL (long call): 3-byte instruction (long call): 3-byte instruction
– 2-byte address2-byte address– Target address within 64K-byte rangeTarget address within 64K-byte range
ACALLACALL (absolute call): 2-byte instruction (absolute call): 2-byte instruction– 11-bit address11-bit address– Target address within 2K-byte rangeTarget address within 2K-byte range
![Page 10: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/10.jpg)
LCALLLCALL
![Page 11: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/11.jpg)
CALL Instruction & Role of StackCALL Instruction & Role of Stack
![Page 12: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/12.jpg)
CALL Instruction & Role of StackCALL Instruction & Role of Stack
![Page 13: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/13.jpg)
Calling SubroutinesCalling Subroutines
![Page 14: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/14.jpg)
Calling SubroutinesCalling Subroutines
![Page 15: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/15.jpg)
ACALL (absolute call)ACALL (absolute call)
![Page 16: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/16.jpg)
Programming EfficientlyProgramming Efficiently
![Page 17: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/17.jpg)
Time Delay Generation & CalculationTime Delay Generation & Calculation
1 instruction = 1 instruction = nn machine cycle machine cycle 1 machine cycle = 12 clock cycles1 machine cycle = 12 clock cycles
![Page 18: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/18.jpg)
Delay CalculationDelay Calculation
![Page 19: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/19.jpg)
Delay Calculation ExampleDelay Calculation Example
![Page 20: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/20.jpg)
Delay Calculation ExampleDelay Calculation Example
![Page 21: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/21.jpg)
Increasing Delay Using NOPIncreasing Delay Using NOP
![Page 22: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/22.jpg)
Large Delay Using Nested LoopLarge Delay Using Nested Loop
![Page 23: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/23.jpg)
REF::NATIONAL TAIWANOCEAN UNIVERSITYREF::NATIONAL TAIWANOCEAN UNIVERSITY國立台灣海洋大學國立台灣海洋大學
University Of Engineering And Technology TaxilaUniversity Of Engineering And Technology Taxila
Chapter 6Chapter 6Arithmetic Instructions and Arithmetic Instructions and ProgramsPrograms
![Page 24: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/24.jpg)
OutlinesOutlines Range of numbers in 8051 unsigned dataRange of numbers in 8051 unsigned data Addition & subtraction instructions for unsigned Addition & subtraction instructions for unsigned
datadata BCD system of data representationBCD system of data representation Packed and unpacked BCD dataPacked and unpacked BCD data Addition & subtraction on BCD dataAddition & subtraction on BCD data Range of numbers in 8051 signed dataRange of numbers in 8051 signed data Signed data arithmetic instructionsSigned data arithmetic instructions Carry & overflow problems & correctionsCarry & overflow problems & corrections
![Page 25: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/25.jpg)
Addition of Unsigned NumbersAddition of Unsigned Numbers ADDADD A, sourceA, source ; A = A + source; A = A + source
![Page 26: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/26.jpg)
ADDC & Addition of 16-bit NumbersADDC & Addition of 16-bit Numbers 13C E73B 8D78 74
+
![Page 27: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/27.jpg)
BCD Number SystemBCD Number System Unpacked BCD: 1 byteUnpacked BCD: 1 byte Packed BCD: 4 bitsPacked BCD: 4 bits
![Page 28: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/28.jpg)
Adding BCD Numbers & DA InstructionAdding BCD Numbers & DA InstructionMOVMOV A,#17HA,#17HADDADD A,#28HA,#28H
MOVMOV A,#47HA,#47H ;A=47H first BCD operand;A=47H first BCD operand MOVMOVB,#25HB,#25H ;B=25 second BCD operand;B=25 second BCD operandADDADD 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 BCDBCD2929 0010 10010010 1001
++ 1818 + + 0001 10000001 10004141 0100 00010100 0001 AC=1AC=1
++ 6 6 + + 0110 01104747 0100 01110100 0111
![Page 29: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/29.jpg)
Subtraction of Unsigned NumbersSubtraction of Unsigned Numbers
SUBBSUBB A, sourceA, source ; A = A – source – C; A = A – source – CYY
SUBB when CY = 0SUBB when CY = 0– Take 2’s complement of subtraend (source)Take 2’s complement of subtraend (source)– Add it to minuendAdd it to minuend– Invert carryInvert carry
![Page 30: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/30.jpg)
Example (Positive Result)Example (Positive Result)
![Page 31: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/31.jpg)
Example (Negative Result)Example (Negative Result)
![Page 32: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/32.jpg)
SUBB When CY = 1SUBB When CY = 1 For multibyte numbersFor multibyte numbers
![Page 33: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/33.jpg)
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. AMOVMOV B,#65HB,#65H ;load 65H in reg. B;load 65H in reg. BMULMUL 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 34: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/34.jpg)
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 AMOVMOV B,#10HB,#10H ;load 10 into B;load 10 into BDIVDIV 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 35: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/35.jpg)
Example ( 1 of 2 )Example ( 1 of 2 )
![Page 36: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/36.jpg)
Example ( 2 of 2 )Example ( 2 of 2 )
![Page 37: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/37.jpg)
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 38: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/38.jpg)
ExampleExample
![Page 39: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/39.jpg)
ExampleExample
![Page 40: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/40.jpg)
ExampleExample
![Page 41: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/41.jpg)
Byte-sized Signed Numbers RangesByte-sized Signed Numbers RangesDecimalDecimal 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 42: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/42.jpg)
Overflow in Signed Number OperationsOverflow in Signed Number Operations
![Page 43: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/43.jpg)
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 44: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/44.jpg)
ExampleExample
![Page 45: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/45.jpg)
ExampleExample
![Page 46: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/46.jpg)
ExampleExample
![Page 47: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/47.jpg)
REF::NATIONAL TAIWANOCEAN UNIVERSITYREF::NATIONAL TAIWANOCEAN UNIVERSITY國立台灣海洋大學國立台灣海洋大學
University Of Engineering And Technology TaxilaUniversity Of Engineering And Technology Taxila
Chapter 7Chapter 7LOGIC INSTRUCTIONS LOGIC INSTRUCTIONS AND PROGRAMSAND PROGRAMS
![Page 48: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/48.jpg)
OutlinesOutlines Define the truth tables for logic functions AND, OR, Define the truth tables for logic functions AND, OR,
XORXOR Code 8051 Assembly language logic function instructionsCode 8051 Assembly language logic function instructions Use 8051 logic instructions for bit manipulationUse 8051 logic instructions for bit manipulation Use compare and jump instructions for program controlUse compare and jump instructions for program control Code 8051 rotate and swap instructionsCode 8051 rotate and swap instructions Code 8051 programs for ASCII and BCD data conversionCode 8051 programs for ASCII and BCD data conversion
![Page 49: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/49.jpg)
ANDAND
XX YY X AND YX AND Y
00 00 00
00 11 00
11 00 00
11 11 11
ANL destination, source ;dest = dest AND sourceANL destination, source ;dest = dest AND source
![Page 50: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/50.jpg)
ORORORL destination, source ;dest = dest OR sourceORL destination, source ;dest = dest OR source
XX YY X AND YX AND Y
00 00 00
00 11 11
11 00 11
11 11 11
![Page 51: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/51.jpg)
XORXORXRL destination, source ;dest = dest XOR sourceXRL destination, source ;dest = dest XOR source
XX YY X AND YX AND Y
00 00 00
00 11 11
11 00 11
11 11 00
XRL A,#04H ;EX-OR A with 0000 0100
![Page 52: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/52.jpg)
XORXOR
![Page 53: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/53.jpg)
XORXOR
![Page 54: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/54.jpg)
CPL (complement accumulator)CPL (complement accumulator)MOVMOV A,#55HA,#55HCPLCPL AA ;now A=AAH;now A=AAH
;0101 0101(55H) becomes ;0101 0101(55H) becomes ;1010 1010 (AAH);1010 1010 (AAH)
![Page 55: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/55.jpg)
Compare instructionCompare instructionCJNE destination, source ,relative addressCJNE destination, source ,relative address
![Page 56: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/56.jpg)
Table 7-1:Carry Flag Setting For CJNE InstructionTable 7-1:Carry Flag Setting For CJNE Instruction
CompareCompare Carry FlagCarry Flagdestination > sourcedestination > source CY = 0CY = 0destination < sourcedestination < source CY = 1CY = 1
CJNE R5,#80,NOT_EQUAL ;check R5 for 80
….;R5=80NOT_EQUAL: JNC NEXT ;jump if R5>80
….;R5<80NEXT: ….
![Page 57: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/57.jpg)
![Page 58: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/58.jpg)
![Page 59: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/59.jpg)
![Page 60: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/60.jpg)
![Page 61: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/61.jpg)
Rotating the bits of A right and leftRotating the bits of A right and leftRRRR AA ;rotate right A;rotate right A
MOV A,#36H ;A=0011 0110RR A ;A=0001 1011RR A ;A=1000 1101RR A ;A=1100 0110RR A ;A=0110 0011
RL A ;rotate left A
![Page 62: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/62.jpg)
MOV A,#72H ;A=0111 0010RL A ;A=1110 0100RL A ;A=1100 1001
![Page 63: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/63.jpg)
Rotating through the carryRotating through the carryRRCRRC A A ;rotate right through carry;rotate right through carry
CLR C ;make CY=0MOV A,#26H ;A=0010 0110RRC A ;A=0001 0011 CY=0RRC A ;A=0000 1001 CY=1RRC A ;A=1000 0100 CY=1
RLC A ;rotate left through carry
![Page 64: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/64.jpg)
SETB C ;make CY=1MOV A,#15H ;A=0001 0101RLC A ;A=0010 1010 CY=0RLC A ;A=0101 0110 CY=0RLC A ;A=1010 1100 CY=0RLC A ;A=0101 1000 CY=1
![Page 65: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/65.jpg)
SWAPSWAP AA
![Page 66: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/66.jpg)
![Page 67: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/67.jpg)
RRC A ;first bit to carryMOV P1.3,C ;output carry as data bitRRC A ;second bit to carryMOV P1.3,C ;output carry as data bitRRC A ;third bit to carryMOV P1.3,C ;output carry as data bit…..
![Page 68: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/68.jpg)
BCD AND ASCII APPLICATION BCD AND ASCII APPLICATION PROGRAMPROGRAM
![Page 69: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/69.jpg)
Packed BCD to ASCII conversionPacked BCD to ASCII conversion
Packed BCDPacked BCD Unpacked BCDUnpacked BCD ASCIIASCII29H29H 02H & 09H02H & 09H 32H & 39H32H & 39H0010 10010010 1001 0000 0010 &0000 0010 & 0011 0010 &0011 0010 &
0000 10010000 1001 0011 10010011 1001
![Page 70: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/70.jpg)
ASCII to packed BCD conversionASCII to packed BCD conversion
Key ASCII Unpacked BCDKey ASCII Unpacked BCD Packed BCDPacked BCD44 34 00000100 34 00000100 77 37 00000111 01000111 or 47H 37 00000111 01000111 or 47H
MOV A,#’4’ ;A=34H, hex for ASCII char 4MOV R1,#’7’ ;R1=37H, hex for ASCII char 7ANL A,#0FH ;mask upper nibble (A=04)ANL R1,#0FH ;mask upper nibble (R1=07)SWAP A ;A=40HORL A,R1 ;A=47H, packed BCD
![Page 71: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/71.jpg)
![Page 72: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/72.jpg)
REF::NATIONAL TAIWANOCEAN UNIVERSITYREF::NATIONAL TAIWANOCEAN UNIVERSITY國立台灣海洋大學國立台灣海洋大學
University Of Engineering And Technology TaxilaUniversity Of Engineering And Technology Taxila
Chapter 8Chapter 8SINGLE-BIT INSTRUCTIONS SINGLE-BIT INSTRUCTIONS AND PROGRAMMINGAND PROGRAMMING
![Page 73: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/73.jpg)
OutlinesOutlines List the 8051 Assembly language instructions for bit List the 8051 Assembly language instructions for bit
manipulationmanipulation Code 8051 instructions for bit manipulation of portsCode 8051 instructions for bit manipulation of ports Explain which 8051 registers are bit-addressableExplain which 8051 registers are bit-addressable Describe which portions of the 8051 RAM are bit-addressableDescribe which portions of the 8051 RAM are bit-addressable Discuss bit manipulation of the carry flagDiscuss bit manipulation of the carry flag Describe the carry flag bit-related instructions of the 8051Describe the carry flag bit-related instructions of the 8051
![Page 74: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/74.jpg)
Single-bit instructionsSingle-bit instructions
![Page 75: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/75.jpg)
I/O ports and bit-addressabilityI/O ports and bit-addressability
The 8051 has four I/O ports, each of which is 8 bits
![Page 76: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/76.jpg)
![Page 77: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/77.jpg)
![Page 78: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/78.jpg)
![Page 79: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/79.jpg)
![Page 80: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/80.jpg)
Checking an input bitChecking an input bitJNB (jump if no bit) ; JB (jump if bit = 1)
![Page 81: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/81.jpg)
Registers and bit-addressabilityRegisters and bit-addressability
![Page 82: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/82.jpg)
![Page 83: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/83.jpg)
Figure 8-2. Bits of the PSW Register
![Page 84: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/84.jpg)
![Page 85: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/85.jpg)
Bit-addressable RAMBit-addressable RAM
![Page 86: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/86.jpg)
![Page 87: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/87.jpg)
![Page 88: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/88.jpg)
Single-bit operations with CYSingle-bit operations with CY
![Page 89: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/89.jpg)
![Page 90: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/90.jpg)
![Page 91: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/91.jpg)
![Page 92: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/92.jpg)
Instructions for reading input portInstructions for reading input port
READING INPUT PINS VS. PORT LATCHREADING INPUT PINS VS. PORT LATCH
In Reading a port:1.Read the status of the input pin2.Read the internal latch of the output port
![Page 93: Chapter 3 JUMP, LOOP and CALL Instructions](https://reader034.fdocuments.in/reader034/viewer/2022042423/56814cf1550346895db9f335/html5/thumbnails/93.jpg)
Reading latch for output portReading latch for output port