SlideShare a Scribd company logo
1 of 46
Download to read offline
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 1
Microprocessors & Microcontroller-1
Prof. Nitin Ahire
Xavier Institute Of Engineering,Mahim
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 2
Instruction Groups
• The 8051 has 255 instructions
– Every 8-bit number from 00 to FF is used as
opcode except for number A5.
• The instructions are grouped into 5 groups
– Arithmetic
– Logic
– Data Transfer
– Boolean
– Branching
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 3
Arithmetic Instructions
• ADD
– 8-bit addition between the accumulator (A) and a
second operand.
• The result is always in the accumulator.
• The CY flag is set/reset appropriately.
• ADDC
– 8-bit addition between the accumulator, a second
operand and the previous value of the CY flag.
• Useful for 16-bit addition in two steps.
• The CY flag is set/reset appropriately.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 4
Example – 16-bit Addition
Add 1E44H to 56CAH. Save the result in R1: R2 registers
ORG 0000H
CLR C ; Clear the CY flag
MOV A, #44H ; The lower 8-bits of the 1st number
ADD A, #CAH ; The lower 8-bits of the 2nd number
MOV R1, A ; The result 0EH will be in R1. CY = 1.
MOV A, #1EH ; The upper 8-bits of the 1st number
ADDC A, #56H ; The upper 8-bits of the 2nd number
MOV R2, A ; The result of the addition is 75H
END
The overall result: 750EH will be in R2:R1. CY = 0.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 5
Arithmetic Instructions
• DA A
– Decimal adjust the accumulator.
• Format the accumulator into a proper 2 digit packed BCD
number.
• Operates only on the accumulator.
• Works only after the ADD instruction.
• SUBB A, source
– Subtract with Borrow. (In the 8051we have only
SUBB)
• Subtract an operand and the previous value of the borrow
(carry) flag from the accumulator.
– A ← A - <operand> - CY.
– The result is always saved in the accumulator.
– The CY flag is set/reset appropriately.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 6
Example – BCD addition
Add 34 to 49 BCD
CLR C ; Clear the CY flag
MOV A, #34H ; Place 1st number in A
ADD A, #49H ; Add the 2nd number.
; A = 7DH
DA A ; A = 83H
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 7
Arithmetic Instructions
• INC
– Increment the operand by one.
• The operand can be a register, a direct address, an
indirect address, the data pointer.
• DEC
– Decrement the operand by one.
• The operand can be a register, a direct address, an
indirect address.
• MUL AB / DIV AB
– Multiply A by B and place result in A:B.
– Divide A by B and place result in A:B.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 8
Logical Operations
• ANL / ORL
– Work on byte sized operands or the CY flag.
• ANL A, Rn
• ANL A, direct
• ANL A, @Ri; i = 0 or 1 only
• ANL A, #data
• ANL direct, A; ANL 0F0,A
• ANL direct, #data; ANL P1,#00001111b
• ANL C, bit; ANL C,P2.2
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 9
Logical Operations
• XRL
– Works on bytes only.
XRL A,#09H
• CPL / CLR
– Complement / Clear.
CPL A
CPL C
– Work on the accumulator or a bit.
• CLR P1.2
• CLR P2.4
• CLR ACC.7
• CLR A
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 10
Logical Operations
• RL / RLC / RR / RRC A
– Rotate the accumulator.
• RL and RR without the carry
• RLC and RRC rotate through the carry.
• SWAP A
– Swap the upper and lower nibbles of the
accumulator.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 11
• Write a program to convert unpacked numbers to
packed number
• Data – convert the number 09h and 02h
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 12
Solution
• Org 0000h
MOV A,#02H; A 02
MOV B,A B 02
MOV A,#09H A 09
SWAP A A 90
ADD A,B A 92
MOV R0,A R0 92
END
Result R0= 92h
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 13
• Write a program to convert packed number to
packed number
• Data – convert the number 92h
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 14
Solution
• ORG 0000H
• MOV A,#92H
• MOV B,A
• ANL A,#F0H
• SWAP A
• MOV R0,A
• MOV A,B
• ANL A,#0FH
• MOV R1,A
• END
Result: R0=09 and R1=02
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 15
Data Transfer Instructions
• MOV
– 8-bit data transfer for internal RAM and the SFR.
• MOV A, Rn MOV A,R0
• MOV A, direct ; MOV A,90H
• MOV A, @Ri ; i = 0 or 1 only
• MOV A, #data MOV A,#34H
• MOV Rn, A MOV R0,A
• MOV Rn, direct ; MOV R0,0E0h
• MOV Rn, #data MOV R1,#35H
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 16
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 17
Data Transfer Instructions
• MOV direct, A
• MOV direct, Rn
• MOV direct, @Ri
• MOV direct, #data
• MOV @Ri, A
• MOV @Ri, direct
• MOV @Ri, #data
MOV TMOD,#39H
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 18
Data Transfer Operations
• MOV ( Single bit )
– 1-bit data transfer involving the CY flag
• MOV C, bit; MOV C, P0.0
• MOV bit, C; MOV P0.0, C
• MOV
– 16-bit data transfer involving the DPTR
• MOV DPTR, #data
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 19
Data Transfer Instructions
• MOVC
– Move Code Byte
• Load the accumulator with a byte from program memory.
• Must use indexed addressing
• MOVC A, @A+DPTR
• MOVC A, @A+PC
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 20
Example
• Example: look up table SQUR has the squares of
values between 0 and 9 and register R3 has the
values 0 to 9.
write a program to fetch the squares from the
look- up table
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 21
Solution
• ORG 0000H
MOV DPTR,# SQUR ; DPTR=0100h
MOV R3,#03h; R3=03h
MOV A,R3; A=03h
MOVC A,@A+DPTR; A=09h
ORG 0100H
SQUR: DB 00,01,04,09,16,25,36,49,64,81
END
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 22
Example
• Assume that an ASC II character string is
stored in on chip ROM starting address 200h.
Write a program to bring each character into
CPU and send it on P1.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 23
solution
• ORG 0000h
MOV DPTR,#200H ;load DPTR
B1: CLR A ; A=0
MOVC A,@A+DPTR ; move data at A+ DPTR into A
JZ EXIT ; exit if last ( null ) char
MOV P1,A
INC DPTR
SJMP B1 ;continue.
EXIT: END
ORG 200h
DB “XAVIER INSTITUTE OF ENGG”,0
END
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 24
On-chip and off-chip ROM
• EA^=VCC
meaning that upon reset 8051 executes the on
chip program first, then when reaches the end of
the on chip ROM it switches to external ROM.
on chip memory size 0000h to 0FFFh (4KB)
off chip memory size 1000h to FFFFh (60KB)
Total memory accessing capacity 64KB
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 25
Roll of RD^ and PSEN^
• For the ROM containing the program code,
PSEN^ is used to fetch the code
• For ROM containing data, the RD^ signal is used
to fetch the data
• To access the external data memory space we
must use the instruction MOVX as described
next.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 26
Data Transfer Instructions
• MOVX
– Data transfer between the accumulator and a byte
from external data memory.
• MOVX A, @Ri
• MOVX A, @DPTR
• MOVX @Ri, A
• MOVX @DPTR, A
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 27
Data Transfer Instructions
• PUSH / POP
– Push and Pop a data byte onto the stack.
– The data byte is identified by a direct address from
the internal RAM locations.
• PUSH DPL
• POP 40H
• PUSH 7
• POP 7
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 28
Data Transfer Instructions
• XCH
– Exchange accumulator and a byte variable
• XCH A, Rn
• XCH A, direct
• XCH A, @Ri
• XCHD
– Exchange lower digit (nibble) of accumulator with the lower
digit of the memory location specified.
• XCHD A, @Ri
• The lower 4-bits of the accumulator are exchanged with
the lower 4-bits of the internal memory location identified
indirectly by the index register.
• The upper 4-bits of each are not modified.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 29
Boolean Operations
• This group of instructions is associated with the
single-bit operations of the 8051.
• This group allows manipulating the individual bits
of bit addressable registers and memory
locations as well as the CY flag.
– The P, OV, and AC flags cannot be directly
altered.
• This group includes:
– Set, clear, and, or ,complement, move.
– Conditional jumps.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 30
Boolean Operations
• CLR
– Clear a bit or the CY flag.
• CLR P1.1
• CLR C
• CLR ACC.2
• SETB
– Set a bit or the CY flag.
• SETB psw.2
• SETB C
• CPL
– Complement a bit.
• CPL 06H ; Complement bit 06H of the bit
addressable memory
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 31
Bank 0
Bank 2
Bank 1
Bank 3
0001020304050607
08090A0B0C0D0E0F
78797A7B7C7D7E7F
00
1F
20
2F
30
7F
4 Reg. BANK 8 bytes each
32 bytes
Bit addressable RAM
16 bytes ( 80 bits)
General purpose RAM
80 bytes
Internal RAM memory organization
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 32
Boolean Operations
• ORL / ANL
– OR / AND a bit with the CY flag.
• ORL C, 20H ; OR bit 20 of bit addressable
memory with the CY flag
• ANL C, 34H ; AND complement of bit 34 of bit
addressable memory with the CY
flag.
• MOV
– Data transfer between a bit and the CY flag.
• MOV C, 3FH ; Copy the CY flag to bit 3F of the
bit addressable memory.
• MOV P1.2, C ; Copy the CY flag to bit 2 of P1.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 33
Unconditional Jump
• LJMP 16 bit address
• SJMP 8 bit address
• AJMP ( Absolute jump)
function: Transfer control unconditionally to a
new address.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 34
Unconditional Jump
• LJMP (long jump) :This is a 3 - byte
instruction the first byte is the opcode and the
next two bytes are the target object.
• LJMP is used to jump to any address location
within 64KB code memory space of the 8051.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 35
Unconditional Jump
• SJMP ( Short jump) : This is a 2 –byte instruction
the first byte is opcode and the second byte is a
singed number displacement, which is added
with the PC of the instruction following the SJMP
to get the target address
• There fore in this jump the target address must
be within -128 to +127 byte of the PC of the
instruction after the SJMP. Generally it called
relative Address.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 36
Branching Instructions
• AJMP ( Absolute jump)
It transfer the program execution to the target
address unconditionally
the target address for this instruction must be
with in 2K byte memory.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 37
Branching Instructions
– Indirect Jump – JMP
• JMP @A + DPTR
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 38
Branching Instructions
• The 8051 provides 2 forms for the CALL
instruction:
– Absolute Call – ACALL
• Uses an 11-bit address similar to AJMP
• The subroutine must be within the same 2K page.
– Long Call – LCALL
• Uses a 16-bit address similar to LJMP
• The subroutine can be anywhere.
– Both forms push the 16-bit address of the next
instruction on the stack and update the stack
pointer.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 39
Branching Instructions
• The 8051 provides 2 forms for the return
instruction:
– Return from subroutine – RET
• Pop the return address from the stack and continue
execution there.
– Return from ISR – RETI
• Pop the return address from the stack.
• Restore the interrupt logic to accept additional interrupts
at the same priority level as the one just processed.
• Continue execution at the address retrieved from the
stack.
• The PSW is not automatically restored.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 40
Branching Instructions
• The 8051 supports 5 different conditional jump
instructions.
– ALL conditional jump instructions use an 8-bit
signed offset.
– Jump on Zero – JZ / JNZ
• Jump if the A == 0 / A != 0
– The check is done at the time of the instruction execution.
– Jump on Carry – JC / JNC
• Jump if the C flag is set / cleared.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 41
Branching Instructions
– Jump on Bit – JB / JNB
• Jump if the specified bit is set / cleared.
• Any addressable bit can be specified.
– Jump if the Bit is set then Clear the bit – JBC
• Jump if the specified bit is set.
• Then clear the bit.
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 42
Branching Instructions
• Compare and Jump if Not Equal – CJNE
– Compare the magnitude of the two operands and
jump if they are not equal.
• The values are considered to be unsigned.
• The Carry flag is set / cleared appropriately.
• CJNE A, direct, rel
• CJNE A, #data, rel
• CJNE Rn, #data, rel
• CJNE @Ri, #data, rel
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 43
Example
• Keep monitoring P1 indefinitely for the
value of 99h. Get out only when P1 has
the value 99h
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 44
solution
MOV P1,#0FFh
Back: MOV A,P1
CJNE A, #99, Back
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 45
Branching Instructions
• Decrement and Jump if Not Zero – DJNZ
– Decrement the first operand by 1 and jump to the
location identified by the second operand if the
resulting value is not zero.
• DJNZ Rn, rel
• DJNZ direct, rel
Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 46
• No Operation
– NOP
Do noting

More Related Content

What's hot

Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacingdeval patel
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction setv Kalairajan
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerSudhanshu Janwadkar
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptxMemonaMemon1
 
DAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdfDAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdfSrikrishna Thota
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086saurav kumar
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontrollerAshish Ranjan
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.pptDr.YNM
 
8086 pin details
8086 pin details8086 pin details
8086 pin detailsAJAL A J
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 

What's hot (20)

Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacing
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
Counters
CountersCounters
Counters
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
DAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdfDAC Interfacing with 8051.pdf
DAC Interfacing with 8051.pdf
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontroller
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
Shift Register
Shift RegisterShift Register
Shift Register
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 

Similar to 8051 micro controllers Instruction set

8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdfMrRRThirrunavukkaras
 
Microprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsMicroprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsArkhom Jodtang
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.pptsteffydean
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)Pratheesh Pala
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarizeHisham Mat Hussin
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxAshokRachapalli1
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineTechnogroovy
 
lb instruments by using microcontroller , Rabi Moirangthem
lb instruments by using microcontroller , Rabi Moirangthemlb instruments by using microcontroller , Rabi Moirangthem
lb instruments by using microcontroller , Rabi MoirangthemRabi Moirangthem
 
digital elctronics
digital elctronicsdigital elctronics
digital elctronicsAsif Iqbal
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructionsihsanjamil
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).pptKanikaJindal9
 
Winter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate TrainingWinter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate TrainingTechnogroovy
 
Digital electronics logic design complete notes.pdf
Digital electronics logic design complete notes.pdfDigital electronics logic design complete notes.pdf
Digital electronics logic design complete notes.pdf022BELEHemant
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction SetDwight Sabio
 

Similar to 8051 micro controllers Instruction set (20)

8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf
 
Microprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsMicroprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructions
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 
8051 micro controller
8051 micro controller8051 micro controller
8051 micro controller
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.ppt
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarize
 
module-3.pptx
module-3.pptxmodule-3.pptx
module-3.pptx
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptx
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects Online
 
lb instruments by using microcontroller , Rabi Moirangthem
lb instruments by using microcontroller , Rabi Moirangthemlb instruments by using microcontroller , Rabi Moirangthem
lb instruments by using microcontroller , Rabi Moirangthem
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
digital elctronics
digital elctronicsdigital elctronics
digital elctronics
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt
 
Winter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate TrainingWinter training,Readymade Projects,Buy Projects,Corporate Training
Winter training,Readymade Projects,Buy Projects,Corporate Training
 
Instruction types
Instruction typesInstruction types
Instruction types
 
Digital electronics logic design complete notes.pdf
Digital electronics logic design complete notes.pdfDigital electronics logic design complete notes.pdf
Digital electronics logic design complete notes.pdf
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction Set
 

More from Nitin Ahire

Microprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireMicroprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireNitin Ahire
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 MicrocontrollerNitin Ahire
 
8085 ppi 8255 and 8155
8085 ppi 8255 and 81558085 ppi 8255 and 8155
8085 ppi 8255 and 8155Nitin Ahire
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051Nitin Ahire
 
8051 singed number concept [compatibility mode]
8051 singed  number concept [compatibility mode]8051 singed  number concept [compatibility mode]
8051 singed number concept [compatibility mode]Nitin Ahire
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1Nitin Ahire
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085Nitin Ahire
 
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085Nitin Ahire
 
Interrupt of 8085
Interrupt of 8085Interrupt of 8085
Interrupt of 8085Nitin Ahire
 

More from Nitin Ahire (10)

Microprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireMicroprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahire
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
8085 ppi 8255 and 8155
8085 ppi 8255 and 81558085 ppi 8255 and 8155
8085 ppi 8255 and 8155
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051
 
8051 singed number concept [compatibility mode]
8051 singed  number concept [compatibility mode]8051 singed  number concept [compatibility mode]
8051 singed number concept [compatibility mode]
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085
 
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085
 
Interrupt of 8085
Interrupt of 8085Interrupt of 8085
Interrupt of 8085
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

8051 micro controllers Instruction set

  • 1. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 1 Microprocessors & Microcontroller-1 Prof. Nitin Ahire Xavier Institute Of Engineering,Mahim
  • 2. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 2 Instruction Groups • The 8051 has 255 instructions – Every 8-bit number from 00 to FF is used as opcode except for number A5. • The instructions are grouped into 5 groups – Arithmetic – Logic – Data Transfer – Boolean – Branching
  • 3. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 3 Arithmetic Instructions • ADD – 8-bit addition between the accumulator (A) and a second operand. • The result is always in the accumulator. • The CY flag is set/reset appropriately. • ADDC – 8-bit addition between the accumulator, a second operand and the previous value of the CY flag. • Useful for 16-bit addition in two steps. • The CY flag is set/reset appropriately.
  • 4. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 4 Example – 16-bit Addition Add 1E44H to 56CAH. Save the result in R1: R2 registers ORG 0000H CLR C ; Clear the CY flag MOV A, #44H ; The lower 8-bits of the 1st number ADD A, #CAH ; The lower 8-bits of the 2nd number MOV R1, A ; The result 0EH will be in R1. CY = 1. MOV A, #1EH ; The upper 8-bits of the 1st number ADDC A, #56H ; The upper 8-bits of the 2nd number MOV R2, A ; The result of the addition is 75H END The overall result: 750EH will be in R2:R1. CY = 0.
  • 5. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 5 Arithmetic Instructions • DA A – Decimal adjust the accumulator. • Format the accumulator into a proper 2 digit packed BCD number. • Operates only on the accumulator. • Works only after the ADD instruction. • SUBB A, source – Subtract with Borrow. (In the 8051we have only SUBB) • Subtract an operand and the previous value of the borrow (carry) flag from the accumulator. – A ← A - <operand> - CY. – The result is always saved in the accumulator. – The CY flag is set/reset appropriately.
  • 6. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 6 Example – BCD addition Add 34 to 49 BCD CLR C ; Clear the CY flag MOV A, #34H ; Place 1st number in A ADD A, #49H ; Add the 2nd number. ; A = 7DH DA A ; A = 83H
  • 7. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 7 Arithmetic Instructions • INC – Increment the operand by one. • The operand can be a register, a direct address, an indirect address, the data pointer. • DEC – Decrement the operand by one. • The operand can be a register, a direct address, an indirect address. • MUL AB / DIV AB – Multiply A by B and place result in A:B. – Divide A by B and place result in A:B.
  • 8. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 8 Logical Operations • ANL / ORL – Work on byte sized operands or the CY flag. • ANL A, Rn • ANL A, direct • ANL A, @Ri; i = 0 or 1 only • ANL A, #data • ANL direct, A; ANL 0F0,A • ANL direct, #data; ANL P1,#00001111b • ANL C, bit; ANL C,P2.2
  • 9. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 9 Logical Operations • XRL – Works on bytes only. XRL A,#09H • CPL / CLR – Complement / Clear. CPL A CPL C – Work on the accumulator or a bit. • CLR P1.2 • CLR P2.4 • CLR ACC.7 • CLR A
  • 10. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 10 Logical Operations • RL / RLC / RR / RRC A – Rotate the accumulator. • RL and RR without the carry • RLC and RRC rotate through the carry. • SWAP A – Swap the upper and lower nibbles of the accumulator.
  • 11. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 11 • Write a program to convert unpacked numbers to packed number • Data – convert the number 09h and 02h
  • 12. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 12 Solution • Org 0000h MOV A,#02H; A 02 MOV B,A B 02 MOV A,#09H A 09 SWAP A A 90 ADD A,B A 92 MOV R0,A R0 92 END Result R0= 92h
  • 13. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 13 • Write a program to convert packed number to packed number • Data – convert the number 92h
  • 14. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 14 Solution • ORG 0000H • MOV A,#92H • MOV B,A • ANL A,#F0H • SWAP A • MOV R0,A • MOV A,B • ANL A,#0FH • MOV R1,A • END Result: R0=09 and R1=02
  • 15. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 15 Data Transfer Instructions • MOV – 8-bit data transfer for internal RAM and the SFR. • MOV A, Rn MOV A,R0 • MOV A, direct ; MOV A,90H • MOV A, @Ri ; i = 0 or 1 only • MOV A, #data MOV A,#34H • MOV Rn, A MOV R0,A • MOV Rn, direct ; MOV R0,0E0h • MOV Rn, #data MOV R1,#35H
  • 16. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 16
  • 17. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 17 Data Transfer Instructions • MOV direct, A • MOV direct, Rn • MOV direct, @Ri • MOV direct, #data • MOV @Ri, A • MOV @Ri, direct • MOV @Ri, #data MOV TMOD,#39H
  • 18. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 18 Data Transfer Operations • MOV ( Single bit ) – 1-bit data transfer involving the CY flag • MOV C, bit; MOV C, P0.0 • MOV bit, C; MOV P0.0, C • MOV – 16-bit data transfer involving the DPTR • MOV DPTR, #data
  • 19. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 19 Data Transfer Instructions • MOVC – Move Code Byte • Load the accumulator with a byte from program memory. • Must use indexed addressing • MOVC A, @A+DPTR • MOVC A, @A+PC
  • 20. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 20 Example • Example: look up table SQUR has the squares of values between 0 and 9 and register R3 has the values 0 to 9. write a program to fetch the squares from the look- up table
  • 21. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 21 Solution • ORG 0000H MOV DPTR,# SQUR ; DPTR=0100h MOV R3,#03h; R3=03h MOV A,R3; A=03h MOVC A,@A+DPTR; A=09h ORG 0100H SQUR: DB 00,01,04,09,16,25,36,49,64,81 END
  • 22. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 22 Example • Assume that an ASC II character string is stored in on chip ROM starting address 200h. Write a program to bring each character into CPU and send it on P1.
  • 23. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 23 solution • ORG 0000h MOV DPTR,#200H ;load DPTR B1: CLR A ; A=0 MOVC A,@A+DPTR ; move data at A+ DPTR into A JZ EXIT ; exit if last ( null ) char MOV P1,A INC DPTR SJMP B1 ;continue. EXIT: END ORG 200h DB “XAVIER INSTITUTE OF ENGG”,0 END
  • 24. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 24 On-chip and off-chip ROM • EA^=VCC meaning that upon reset 8051 executes the on chip program first, then when reaches the end of the on chip ROM it switches to external ROM. on chip memory size 0000h to 0FFFh (4KB) off chip memory size 1000h to FFFFh (60KB) Total memory accessing capacity 64KB
  • 25. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 25 Roll of RD^ and PSEN^ • For the ROM containing the program code, PSEN^ is used to fetch the code • For ROM containing data, the RD^ signal is used to fetch the data • To access the external data memory space we must use the instruction MOVX as described next.
  • 26. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 26 Data Transfer Instructions • MOVX – Data transfer between the accumulator and a byte from external data memory. • MOVX A, @Ri • MOVX A, @DPTR • MOVX @Ri, A • MOVX @DPTR, A
  • 27. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 27 Data Transfer Instructions • PUSH / POP – Push and Pop a data byte onto the stack. – The data byte is identified by a direct address from the internal RAM locations. • PUSH DPL • POP 40H • PUSH 7 • POP 7
  • 28. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 28 Data Transfer Instructions • XCH – Exchange accumulator and a byte variable • XCH A, Rn • XCH A, direct • XCH A, @Ri • XCHD – Exchange lower digit (nibble) of accumulator with the lower digit of the memory location specified. • XCHD A, @Ri • The lower 4-bits of the accumulator are exchanged with the lower 4-bits of the internal memory location identified indirectly by the index register. • The upper 4-bits of each are not modified.
  • 29. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 29 Boolean Operations • This group of instructions is associated with the single-bit operations of the 8051. • This group allows manipulating the individual bits of bit addressable registers and memory locations as well as the CY flag. – The P, OV, and AC flags cannot be directly altered. • This group includes: – Set, clear, and, or ,complement, move. – Conditional jumps.
  • 30. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 30 Boolean Operations • CLR – Clear a bit or the CY flag. • CLR P1.1 • CLR C • CLR ACC.2 • SETB – Set a bit or the CY flag. • SETB psw.2 • SETB C • CPL – Complement a bit. • CPL 06H ; Complement bit 06H of the bit addressable memory
  • 31. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 31 Bank 0 Bank 2 Bank 1 Bank 3 0001020304050607 08090A0B0C0D0E0F 78797A7B7C7D7E7F 00 1F 20 2F 30 7F 4 Reg. BANK 8 bytes each 32 bytes Bit addressable RAM 16 bytes ( 80 bits) General purpose RAM 80 bytes Internal RAM memory organization
  • 32. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 32 Boolean Operations • ORL / ANL – OR / AND a bit with the CY flag. • ORL C, 20H ; OR bit 20 of bit addressable memory with the CY flag • ANL C, 34H ; AND complement of bit 34 of bit addressable memory with the CY flag. • MOV – Data transfer between a bit and the CY flag. • MOV C, 3FH ; Copy the CY flag to bit 3F of the bit addressable memory. • MOV P1.2, C ; Copy the CY flag to bit 2 of P1.
  • 33. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 33 Unconditional Jump • LJMP 16 bit address • SJMP 8 bit address • AJMP ( Absolute jump) function: Transfer control unconditionally to a new address.
  • 34. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 34 Unconditional Jump • LJMP (long jump) :This is a 3 - byte instruction the first byte is the opcode and the next two bytes are the target object. • LJMP is used to jump to any address location within 64KB code memory space of the 8051.
  • 35. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 35 Unconditional Jump • SJMP ( Short jump) : This is a 2 –byte instruction the first byte is opcode and the second byte is a singed number displacement, which is added with the PC of the instruction following the SJMP to get the target address • There fore in this jump the target address must be within -128 to +127 byte of the PC of the instruction after the SJMP. Generally it called relative Address.
  • 36. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 36 Branching Instructions • AJMP ( Absolute jump) It transfer the program execution to the target address unconditionally the target address for this instruction must be with in 2K byte memory.
  • 37. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 37 Branching Instructions – Indirect Jump – JMP • JMP @A + DPTR
  • 38. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 38 Branching Instructions • The 8051 provides 2 forms for the CALL instruction: – Absolute Call – ACALL • Uses an 11-bit address similar to AJMP • The subroutine must be within the same 2K page. – Long Call – LCALL • Uses a 16-bit address similar to LJMP • The subroutine can be anywhere. – Both forms push the 16-bit address of the next instruction on the stack and update the stack pointer.
  • 39. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 39 Branching Instructions • The 8051 provides 2 forms for the return instruction: – Return from subroutine – RET • Pop the return address from the stack and continue execution there. – Return from ISR – RETI • Pop the return address from the stack. • Restore the interrupt logic to accept additional interrupts at the same priority level as the one just processed. • Continue execution at the address retrieved from the stack. • The PSW is not automatically restored.
  • 40. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 40 Branching Instructions • The 8051 supports 5 different conditional jump instructions. – ALL conditional jump instructions use an 8-bit signed offset. – Jump on Zero – JZ / JNZ • Jump if the A == 0 / A != 0 – The check is done at the time of the instruction execution. – Jump on Carry – JC / JNC • Jump if the C flag is set / cleared.
  • 41. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 41 Branching Instructions – Jump on Bit – JB / JNB • Jump if the specified bit is set / cleared. • Any addressable bit can be specified. – Jump if the Bit is set then Clear the bit – JBC • Jump if the specified bit is set. • Then clear the bit.
  • 42. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 42 Branching Instructions • Compare and Jump if Not Equal – CJNE – Compare the magnitude of the two operands and jump if they are not equal. • The values are considered to be unsigned. • The Carry flag is set / cleared appropriately. • CJNE A, direct, rel • CJNE A, #data, rel • CJNE Rn, #data, rel • CJNE @Ri, #data, rel
  • 43. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 43 Example • Keep monitoring P1 indefinitely for the value of 99h. Get out only when P1 has the value 99h
  • 44. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 44 solution MOV P1,#0FFh Back: MOV A,P1 CJNE A, #99, Back
  • 45. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 45 Branching Instructions • Decrement and Jump if Not Zero – DJNZ – Decrement the first operand by 1 and jump to the location identified by the second operand if the resulting value is not zero. • DJNZ Rn, rel • DJNZ direct, rel
  • 46. Msc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMsc. Ivan A. Escobar BroitmanMicroprocessors 1 46 • No Operation – NOP Do noting