Professional Documents
Culture Documents
8051 Instructions
❖ 8051 instructions consist of 1 byte of opcode and 0 to 2 bytes of operands.
❖ The instructions use 8 bit register A, B, R0, R1, R2, R3, R4, R5, R6, R7 and also 16 bit
registers, DPTR (data pointer) and PC (program counter).
❖ The instructions (Total 111) of 8051 can be broadly classified under the following headings:
1. Data transfer instructions
2. Arithmetic instructions
3. Logical instructions
4. Branch instructions
5. Subroutine instructions
6. Bit manipulation (Boolean) instructions
✓ The following notations are used in the description of the instructions.
✓ Rn means, any of the eight registers (R0 to R7) in the selected banks.
✓ Ri means either of the pointing registers (R0 or R1) in the selected banks.
✓ M means internal data memory.
✓ E.D.M. means external data memory.
✓ P.M. means internal or external program memory DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
A List of the MCS@-51 Data Transfer Instructions that Access Internal Data Memory Space.
DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
Assuming 12MHz clock
1
12-03-2023
❖ Table shows the two instructions that are available for reading lookup tables in Program
Memory. Since these instructions access only Program Memory, the lookup tables can only be
read, not updated. The mnemonic used is MOVC for “move constant”.
❖ If the table access is to external Program Memory, then the read strobe is PSEN.
❖ The first MOVC instruction in table can accommodate a table of up to 256 entries, numbered 0
through 255. The number of the desired entry is loaded into the Accumulator, and the Data
Pointer is setup to point to beginning of the table. Then MOVC A,@A+DPTR copies the
desired table entry into the Accumulator.
The MCS@-51 Lookup Table Read Instructions DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
2
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
3
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
4
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
5
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
6
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
7
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
8
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Exchange the
digit
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
9
12-03-2023
Arithmetic Instructions
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
10
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
11
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
12
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
13
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
14
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
15
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
16
12-03-2023
Arithmetic Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
17
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
18
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
19
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
20
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
21
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
22
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
23
12-03-2023
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Logical Instructions
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
24
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
25
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
26
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
27
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
28
12-03-2023
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
29
12-03-2023
❖ An LED is connected to pin P1.7. Write a program to toggle the LED forever.
LED BIT P1.7 ;using BIT directive
HERE: CPL LED ;toggle LED
LCALL DELAY ;delay
SJMP HERE ;repeat forever
❖ A switch is connected to pin P1.7 and an LED to pin P2.0. Write a program to get the
status of the switch and send it to the LED.
SW BIT P1.7 ;assign bit
LED BIT P2.0 ;assign bit
HERE: MOV C,SW ;get the bit from the port
MOV LED,C ;send the bit to the port
SJMP HERE ;repeat forever
DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
Jump Instruction's
❖ The table lists a single “JMP addr” instruction, but in fact there are three - SJMP, LJMP
and AJMP - which differ in the format of the destination address.
❖ JMP is a generic mnemonic which can be used if the programmer does not care which
way the jump is encoded.
30
12-03-2023
❖ Table shows the list of conditional jumps available to the MCS-51 user.
❖ All of these jumps specify the destination address by the relative offset method and so are
limited to a jump distance of –128 to +127 bytes from the instruction following the conditional
jump instruction.
❖ Important to note, however, the user specifies to the assembler the actual destination
address the same way as the other jump as a label or a 8-bit constant.
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
31
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
32
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
33
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
34
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
35
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
36
12-03-2023
Jump instruction's
S. P. Gimenez, 8051 Microcontrollers, DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
# Springer International Publishing AG, part of Springer Nature 2019, https://doi.org/10.1007/978-3-319-76439-9
37
12-03-2023
Example
Analyze the stack for the first LCALL instruction in the following program.
01 0000 ORG 0
02 0000 74 55 BACK: MOV A,#55H ;load A with 55H
03 0002 F5 90 MOV P1,A ;send 55H to port 1
04 0004 7C 99 MOV R4,#99H
05 0006 7D 67 MOV R5,#67H
06 0008 12 03 00 LCALL DELAY ;time delay
07 000B 74 AA MOV A,#0AAH ;load A with AA
08 000D F5 90 MOV P1,A ;send AAH to port 1
09 000F 12 03 00 LCALL DELAY
10 0012 80 EC SJMP BACK ;keep doing this
11 0014 ;————————this is the delay subroutine
12 0300 ORG 300H
13 0300 C0 04 DELAY: PUSH 4 ;PUSH R4
14 0302 C0 05 PUSH 5 ;PUSH R5
15 0304 7C FF MOV R4,#0FFH ;R4=FFH
16 0306 7D FF NEXT: MOV R5,#0FFH ;R5=255
17 0308 DD FE AGAIN: DJNZ R5,AGAIN
18 030A DC FA DJNZ R4,NEXT
19 030C D0 05 POP 5 ;POP into R5
20 030E D0 04 POP 4 ;POP into R4
21 0310 22 RET ;return to caller
22 0311 END ;end of asm file
DR. ASHOK KHERODIA, ECE DEPARTMENT, IIIT KOTA
Example
❖ First notice that for the PUSH and POP instructions we must specify the
direct address of the register being pushed or popped. Here is the stack
frame.
38