8051 instruction set
8051 instruction set
INSTRUCTION SET
Introduction
1. Register addressing.
2. Direct addressing.
3. Register indirect addressing.
4. Immediate addressing.
5. Index addressing.
Register Addressing Mode
● For example;
● For example;
● For example;
● For example;
● For example;
DPTR
ORG 0000H
MOV R1,#05 ;Counter
MOV R0,#30H ;Source
MOV DPTR,#2000H ;Destination
back:MOV A,@R0
MOVX @DPTR,A ;A->ext destn
INC R0 ;Source increment
INC DPTR ;destination increment
DJNZ R1,back
END
Arithmetic Instructions
● ADD A, Rn A = A + Rn 1
● ADD A, Rx A = A + Rx 2
● AAD A, @ Ri A = A+ Ri 1
Arithmetic Instructions
● ADD A, # X A = A + Byte 2
● ADDC A, Rn A = A + Rn + C 1
● ADDC A , Rx A = A + Rx + C 2
Arithmetic Instructions
● ADDC A, @ Ri A = A + Ri + C 1
● ADDC A, # X A = A + Byte + C 2
● SUBB A, Rn A = A – Rn – 1 1
Arithmetic Instructions
● SUBB A, Rx A = A – Rx – 1 2
● SUBB A, @ Ri A = A – Ri – 1 1
● SUBB A, # X A = A – Byte – 1 2
Arithmetic Instructions
● INC A A=A+1 1
● INC Rn Rn = Rn + 1 1
● INC Rx Rx = Rx + 1 2
Arithmetic Instructions
● INC @ Ri Ri = Ri + 1 1
● DEC A A=A–1 1
● DEC Rn Rn = Rn – 1 1
Arithmetic Instructions
● DEC Rx Rx = Rx – 1 2
● DEC @ Ri Ri = Ri – 1 1
● MUL AB B:A = A * B 1
● DIV AB A = [A/B] 1
● DA A Decimal adjustment of 1
accumulator according to BCD code
8051 Program to Multiply two 8 Bit
numbers
MOV R0, #20H;set source address 20H to R0
MOV R1, #30H;set destination address 30H to R1
MOV A, @R0;take the first operand from source to register A
INC R0; Point to the next location
MOV B,@R0;take the second operand from source to register B
MUL AB ;Multiply A and B
MOV @R1, B; Store higher order byte to 30H
INC R1; Increase R1 to point to the next location
MOV @R1, A;Store lower order byte to 31H
HALT: SJMP HALT ; Stop the program
ORG 0000H
MOV A, #02H (comment x=2)
MOV B,#03H (n=3)
MOV R0,B (move 03 to R0)
MOV R1,A (move 02 to R1)
MOV R2,#01 (for multiplying put R2=01)
L1: MOV A,R2 (move R2=1 to A)
MOV B,R1 (B=02)
MUL AB (Result =2)
DEC R0 (R0=3-1)
MOV R2,A (Result in A=2 moved to R2)
CJNE R0,#00H, L1 (Repeat till n=0)
MOV A,R2 (Result in R2 moved to A)
END
Logical Instructions
● RL A (An + 1) (An) 1
(A0) (A7)
● RLC (An + 1) (An) 1
(A0) (C)
(C) (A7)
Logical Instructions
● RR A (An) (An + 1) 1
(A7) (A0)
● CLR C (C=0) 1
● SETB C (C=1) 1
Logical Instructions On Bits
● CPL C (1 = 0, 0 = 1) 1
● NOP No operation 1
Summary
● Instruction set.
● Addressing modes.
● Data transfer instruction.
● Arithmetic instruction.
● Logical instruction.
● Logical operation on bits.