Mod4 3 8051 Instrns
Mod4 3 8051 Instrns
Mod4 3 8051 Instrns
ADD, ADDC: Add Acc. (With Carry) JMP: Jump to Address RET: Return From Subroutine
AJMP: Absolute Jump JNB: Jump if Bit Not Set RETI: Return From Interrupt
ANL: Bitwise AND JNC: Jump if Carry Not Set RL: Rotate Accumulator Left
CJNE: Compare & Jump if Not Equal JNZ: Jump if Acc. Not Zero RLC: Rotate Acc. Left Through Carry
CLR: Clear Register JZ: Jump if Accumulator Zero RR: Rotate Accumulator Right
CPL: Complement Register LCALL: Long Call RRC: Rotate Acc. Right Through Carry
DIV: Divide Accumulator by B MOVC: Move Code Memory SUBB: Sub. From Acc. With Borrow
DJNZ: Dec. Reg. & Jump if Not Zero MOVX: Move Extended Memory SWAP: Swap Accumulator Nibbles
JBC: Jump if Bit Set and Clear Bit ORL: Bitwise OR XRL: Bitwise Exclusive OR
MOV DPTR,#7634H
MOV DPL,#34H
MOV DPH,#76H
Note 1:
MOV A,#72H ≠ MOV A,72H
After instruction “MOV A,72H ” the content of 72’th byte of RAM will
replace in Accumulator.
Note 2:
MOV A,R3 ≡ MOV A,3
ADD A, Source ;A=A+SOURCE
ADD A,#6 ;A=A+6
SETB C ; CY=1
SETB P0.0 ;bit 0 from port 0 =1
SETB P3.7 ;bit 7 from port 3 =1
SETB ACC.2 ;bit 2 from ACCUMULATOR =1
SETB 05 ;set high D5 of RAM loc. 20h
Note:
INC R7
DEC A
DEC 40H ; [40]=[40]-1
RR – RL – RRC – RLC A
EXAMPLE:
RR A
RR:
RRC: C
RL:
RLC:
C
ANL - ORL – XRL
Bitwise Logical Operations:
AND, OR, XOR
EXAMPLE:
MOV R5,#89H
ANL R5,#08H
JB Jump if bit=1
Solution:
MOV A,#0
MOV R2,#10
AGAIN: ADD A,#03
DJNZ R2,AGAIN ;repeat until R2=0 (10 times)
MOV R5,A
LJMP(long jump)
LJMP is an unconditional jump. It is a 3-byte instruction. It
allows a jump to any memory location from 0000 to FFFFH.
AJMP(absolute jump)
In this 2-byte instruction, It allows a jump to any memory
location within the 2k block of program memory.
SJMP(short jump)
In this 2-byte instruction. The relative address range of 00-
FFH is divided into forward and backward jumps, that is ,
within -128 to +127 bytes of memory relative to the address of
the current PC.
CALL Instructions
Another control transfer instruction is the CALL instruction,
which is used to call a subroutine.
• LCALL(long call)
This 3-byte instruction can be used to call subroutines
located anywhere within the 64K byte address space
of the 8051. (absolute call)
• ACALL
ACALL is 2-byte instruction. the target
address of the subroutine must be within 2K
byte range.
Example:
Write a program to copy a block of 10 bytes from RAM location
starting at 37h to RAM location starting at 59h.
Solution:
MOV R0,#37h ; source pointer
MOV R1,#59h ; dest pointer
MOV R2,#10 ; counter
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
Decimal Addition
156 + 248
. 100's 10's 1's
. 1 5 6
+ 2 4 8
= 4 0 4 16 Bit Addition
1A44 + 22DB = 3D1F
. 1 A 4 4
+ 2 2 D B
= 3 D 1 F
Performing the Addition with 8051
. 65536's 256's 1's
. R6 R7
+ R4 R5
= R1 R2 R3
1.Add the low bytes R7 and R5, leave the answer in R3.
2.Add the high bytes R6 and R4, adding any carry from step 1, and leave the answer in R2.
ADDC A,R4 ;Add the second high-byte to the accumulator, plus carry.
MOV R1,A ;Move the answer to the highest byte of the result
The Whole Program
;Load the first value into R6 and R7
MOV R6,#1Ah
MOV R7,#44h
;Load the first value into R4 and R5
MOV R4,#22h
MOV R5,#0DBh
;Call the 16-bit addition routine LCALL ADD16_16
ADD16_16: