3. MOV INSTRUCTION
The MOV instruction moves data bytes/bits
between the two specified operands. The byte/bit
specified by the second operand is copied to the
location specified by the first operand
The source data byte/bit is not affected.
No other register or flag is affected.
MOV destination, source ;copy source to dest.
MOV A,#55H ;load value 55H into reg. A
4. MOV A,#35h;
moving the 35h to the register A
MOV 35h,45h;
moving the content of memory location 45h to
the memory location 35h,
Here
#35h is a data,
35h is a memory location.
5. MOV 30h,A;
moving the content of reg. A to the
memory location 30h,
MOV A,30h;
MOV A,R1;
moving the content of reg. R1 to the
reg. A
6. MOV 3,A; = MOV R3,A;
MOV A,@R3;
moving the content of memory
pointed to by R3 to A;
MOV @R3,A;
moving the content of reg. A to the
memory pointed to by reg.R3
7. MOV <dest-bit>,<src-bit>
Function: To move bit data
One of the operands must be the carry
flag
Example: MOV P1.3,C;
moves the carry bit to 3rd bit of port1
if C=1; the output of P1.3 is high,
if C=0; the output of P1.3 is low,
8. MOV DPTR,16bit data
Loads the data pointer with 16 bit
constant,
This is 3 byte instruction,
Data stored in 2nd and 3rd bytes of the
instruction
MOV DPTR, # 4567H
DPL=67H;(lower byte)
DPH=45H;(higher byte)
9. MOV DPTR, # 4567H;
MOV DPL,#67H;
= MOV DPH,#45H;
MOV R1,R2; it is not possible
10. MOVC A,@A+ <base-reg>
these instructions load the accumulator with a
code byte or constant from program memory
The address of the byte fetched is the sum
of the original unsigned 8-bit Accumulator
contents and the contents of a 16-bit base
register
Base register may be either the Data Pointer or
the PC
11. Example:
Look-up table SQUR has the of values between 0
to 4,
ORG 100H
SQUR: DB 0,1,4,9,16
program to fetch the square value of 4
ORG 0H
MOV A,#4H;
MOV DPTR,100H;
MOVC A,@A+DPTR;
END;
12. MOVX <dest-byte>,<src-byte>
The MOVX instructions transfer data
between the Accumulator and a byte of
external data memory,
This data space must be connected
externally
Address of external memory being
accessed can be 16-bit or 8-bit
for 16 bit--- DPTR
8 bit----R0 or R1
13. 16 Bit address data transfer:
MOVX @DPTR,A;
this moves the contents of the
accumulator to the external memory
location whose address is pointed to by
DPTR,
MOVX A,@DPTR;
this moves into the accumulator a byte
from external memory whose address is
pointed to by DPTR,
14. 8 Bit address data transfer
MOVX A,@R1;
This moves to the accumulator to the
external memory whose 8-bit address is
pointed to by R0
MOVX @R1,A;
This moves a byte from register into
external memory location whose 8-bit
address is held by R0
15. EXAMPLE PROGRAM USING
MOVX INSTRUCTION..
An external ROM uses the 8051 data
space to store the look-up table (starting
at 1000H) for DAC data. Write a
program to read 30 Bytes of these data
and send it to P1.
17. BRANCHING INSTRUCTIONS
Program branching instructions are used
to control the flow of actions in program.
Some instructions provide decision
making capabilities and transfer control
to other parts of program.
eg., Unconditional and conditional
branches.
18. SJUMP(short jump):
2 byte instruction
1st byte opcode
2nd byte relative address of target
location
relative address range is 00 – FFH,
All conditional jumps are short jumps
Ex: SJUMP HERE;
after executing this instruction it jumps to
HERE label
19.
20. LJUMP(long jump):
Unconditional long jump
3byte instruction
1st byte for op-code
2nd and 3rd byte for 16 bit address of
target location
22. JZ AND JNZ
INSTRUCTIONS
JZ label ; jump if A=0
Can be used only for register A, not
any other register.
flag registers will not be affected
JNZ label; jump if A is not zero
23. DJNZ INSTRUCTION
DJNZ reg, Label;
The register is decremented.
If it is not zero, it jumps to the target
address referred to by the label.
Prior to the start of loop the register is
loadel with the counter for the number
of repetitions.
Counter can be R0 – R7 or RAM
location.
24. Example
Program to complement the
accumulator 3 times
ORG 0H;
MOV A,0Fh;
MOV R3,3;
HERE: CPL A;
DJNZ R3,HERE;
END
25. EXAMPLE:
Write a program to (a) load the accumulator
with the value 55H, and (b) complement the
ACC 700 times.
MOV A,#55H ;A=55H
MOV R3,#10 ;R3=10, outer loop count
NEXT: MOV R2,#70 ;R2=70, inner loop count
AGAIN: CPL A ;complement A register
DJNZ R2,AGAIN ;repeat it 70 times
DJNZ R3,NEXT
26. JNC INSTRUCTION
JNC label ;jump if no carry, CY=0
If CY = 0, the CPU starts to fetch and
execute instruction from the address of
the label.
If CY = 1, it will not jump but will execute
the next instruction below JNC.
All conditional jumps are short jumps
The address of the target must within
-128 to +127 bytes of the contents of PC
28. CALL instructions
To call a user defined functions in
program
Transfer control to a subroutine
Flags are not affected
RET must be the last instruction of
subroutine
These are two types
1) ACALL(absolute call)
2) LCALL (long call)
29. ACALL:
2 byte instruction
5 bits are used for op-code
remaining 11 bits are used for
subroutine target address
Target address must be within 2K byte
Ex: ACALL label;
here label address should be 2K byte
only
30. LCALL:
3 byte instruction
1st byte for op-code
2nd and 3rd for target address of the
subroutine
Subroutine address located anywhere
within 64K byte
Ex: LCALL label;
31.
32. Program to display 5 and 4 digits in seven
segment display with delay:
ORG 0H;
MOV P1,#05DH;
ACALL DELAY;
MOV P1,#026H;
ACALL DELAY;
END;
DELAY: MOV R3,#55; (count=55)
HERE: DJNZ R3,HERE;(loop)
RET;
33. TIME DELAY
CALCULATIONS
ž CPU executing an instruction takes a
certain number of clock cycles. These
are referred as to as machine cycles.
ž In original 8051, one machine cycle lasts
12 oscillator periods.
ž Find the period of the machine cycle for
11.0592 MHz crystal frequency?
35. PROBLEM:
ž For 8051 system of 11.0592
MHz, find how long it takes to
execute each instruction.
(a) MOV R3,#55 (b) DEC R3 (c)
DJNZ R2 target
(d) LJMP (e) SJMP (f) NOP (g)
MUL AB
37. Find the size of the delay in following program,
if the crystal frequency is 11.0592MHz.
MACHINE CYCLE
DELAY: MOV R3,#250 1
HERE: NOP 1
NOP 1
NOP 1
NOP 1
DJNZ R3,HERE 2
RET 2
38. SOLUTION
ž The time delay inside HERE
loop is [250(1+1+1+1+2)]x1.085μs
= 1627.5μs. Adding the two
instructions outside loop we
have 1627.5μs + 3 x 1.085μs =
1630.755μs.