university of engineering and technology taxila ref::national taiwanocean university...
TRANSCRIPT
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
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
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
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
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
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
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
Addition of Unsigned NumbersAddition of Unsigned Numbers
ADDADD A, sourceA, source ; A = A + source; A = A + source
BCD Number SystemBCD Number System
Unpacked BCD: 1 byteUnpacked BCD: 1 byte Packed BCD: 4 bitsPacked BCD: 4 bits
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 10000001 1000
4141 0100 00010100 0001 AC=1AC=1
++ 6 6 + + 0110 0110
4747 0100 01110100 0111
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
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
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
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
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
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
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
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
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
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
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
CPL (complement accumulator)CPL (complement accumulator)MOVMOV A,#55HA,#55H
CPLCPL AA ;now A=AAH;now A=AAH
;0101 0101(55H) becomes ;0101 0101(55H) becomes ;1010 1010 (AAH);1010 1010 (AAH)
Compare instructionCompare instructionCJNE destination, source ,relative addressCJNE destination, source ,relative address
Table 7-1:Carry Flag Setting For CJNE InstructionTable 7-1:Carry Flag Setting For CJNE Instruction
CompareCompare Carry FlagCarry Flag
destination > sourcedestination > source CY = 0CY = 0
destination < 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: ….
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
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
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
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…..
Packed BCD to ASCII conversionPacked BCD to ASCII conversion
Packed BCDPacked BCD Unpacked BCDUnpacked BCD ASCIIASCII
29H29H 02H & 09H02H & 09H 32H & 39H32H & 39H
0010 10010010 1001 0000 0010 &0000 0010 & 0011 0010 &0011 0010 &
0000 10010000 1001 0011 10010011 1001
ASCII to packed BCD conversionASCII to packed BCD conversion
Key ASCII Unpacked BCDKey ASCII Unpacked BCD Packed BCDPacked BCD
44 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
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
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
I/O ports and bit-addressabilityI/O ports and bit-addressability
The 8051 has four I/O ports, each of which is 8 bits
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