Sunteți pe pagina 1din 17

Control Transfer Instructions

Jump, Loop, and Call

ECE473/573 1
Microprocessor System Design, Dr. Shiue
Jump Instructions
JZ label ; Jump if A=0
JNZ label ; Jump if A!=0

DJNZ reg, label ; Decrement and Jump if A (or reg.) !=0


CJNE A, byte ; Compare and Jump if A!=byte
CJNE reg, #data ; Compare and Jump if byte!=data

JC ; Jump if Carry=1
JNC ; Jump if Carry=0
JB ; Jump if bit =1
JNB ; Jump if bit =0
JBC ; Jump if bit=1 and clear bit

ECE473/573 2
Microprocessor System Design, Dr. Shiue
DJNZ
Decrement and Jump if not zero (DJNZ)
DJNZ register, label
Ex1: Count from 1 to 20 and sent the count to P1.
Ex2: Add 3 to the ACC ten times.
Ex3: What is the maximum number of times that the loop
in the Ex2 can be repeated?
Ex4: Write a program to (a) add the ACC with the value
55H, and (b) complement the ACC 700 times.

ECE473/573 3
Microprocessor System Design, Dr. Shiue
JZ
JZ: Jump if A=0
JZ label
Ex1:
MOV A, R0
JZ Over ; jump if A=0
MOV A, R1
JZ Over ; jump if A=0

Over:

ECE473/573 4
Microprocessor System Design, Dr. Shiue
JNZ, JNC, and JC
JNZ: Jump if A!=0
JNZ label
Ex1: Write a program to determine if R5 contains the value
of 0. If so, put 55H in it.

JNC: Jump if C=0


JNC label

JC: Jump if C=1


JC label

ECE473/573 5
Microprocessor System Design, Dr. Shiue
JNC Examples
JNC: Jump if C=0
JNC label
Ex1: Find the sum of the values 79H, F5H, and E2H. Put
the sum in registers R0 (low byte) and R5 (high byte)

ECE473/573 6
Microprocessor System Design, Dr. Shiue
Uncondition Jump
LJMP: 3-byte instruction

0000

64KB
ROM

FFFF

ECE473/573 7
Microprocessor System Design, Dr. Shiue
Uncondition Jump
SJMP: 2-byte instruction
(Range: -128 (backward) ~ +127 (forward) bytes)

00

256B
ROM

FF

ECE473/573 8
Microprocessor System Design, Dr. Shiue
Jump Forward and Backward
Ex1: Using the following list file, verify the jump forward
address calculation.
lines PC Opcode Instructions
1 0000 ORG 0
2 0000 7800 MOV R0, #0
3 0002 7455 MOV A, #55H
0006+03
=0009 4 0004 6003 JZ Next Jump forward!
5 0006 08 INC R0
6 0007 04 Again: INC A
7 0008 04 INC A
8 0009 2477 Next: ADD A, #77H
9 000B 5005 JNC Over Jump forward!

ECE473/573 9
Microprocessor System Design, Dr. Shiue
Jump Forward and Backward
000D+05
=0012 lines PC Opcode Instructions
10 000D E4 CLR A
11 000E F8 MOV R0, A
12 000F F9 MOV R1, A
13 0010 FA MOV R2, A
14 0011 FB MOV R3, A
0015+F2 15 0012 2B Over: ADD A, R3
=0107
16 0013 50F2 JNC Again Jump backward!
0017+FE
17 0015 80FE Here: SJMP Here Jump backward!
=0115
18 0017 END

ECE473/573 10
Microprocessor System Design, Dr. Shiue
LCALL (Long Call)
LCALL: 3-byte instruction 0000
When subroutine is called
Control is transferred to that subroutine
64KB
Processor saves the PC onto the Stack
ROM
and begins to fetch instructions from
new location.
RET (return to caller)  POP from
Stack to PC
FFFF

Ex1:Write a program to toggle all the bits of port 1 by


sending to it the values 55H and AAH continuously. Put a
time delay in between each issuing of data to port 1. (This
program is used to test the ports of the 8051)
ECE473/573 11
Microprocessor System Design, Dr. Shiue
Main Program and Calls
ORG 0
Main: LCALL Sub_1
LCALL Sub_2
LCALL Sub_3
Here: SJMP Here ; end of main
Sub_1: .
RET : end of Sub_1
Sub_2: .
RET : end of Sub_2
Sub_3: .
RET : end of Sub_3
END

ECE473/573 12
Microprocessor System Design, Dr. Shiue
ACALL (Absolute Call)
ACALL: 2-byte instruction
ACALLs target address must be with in a 2KB range

0000

2KB
ROM
=2*210
=211
07FF

ECE473/573 13
Microprocessor System Design, Dr. Shiue
Time Delay Generation and Calculation
Crystal frequency (XTAL): 4MHz ~ 30MHz
Using 11.0592MHz to make the 8051 compatible with the serial port
of the IBM PC.
Ex1: Find the period of the machine cycle (a) 11.0592MHz
(b) 16MHz (c) 20MHz
Ex2: For an 8051 system of 11.0592 MHz, find how long it takes to
execute each of the following instructions
MOV R3, #55H 1
DEC R3 1
DJNZ R2, target 2
LJMP 2
SJMP 2
NOP 1
MUL AB 4

ECE473/573 14
Microprocessor System Design, Dr. Shiue
Delay Calculation
Ex3: Find the size of the delay in the following program if
XTAL =11.0592MHz

MOV A, #55H
Again: MOV P1, A
ACALL Delay
CPL A
SJMP Again

Delay: MOV R3, #200


Here: DJNZ R3, Here
RET

ECE473/573 15
Microprocessor System Design, Dr. Shiue
NOP
NOP is used for increasing the delay
Ex4: Find the time delay for the following subroutine,
XTAL=11.0592MHz

Delay: MOV R3, #250


Here: NOP
NOP
NOP
NOP
DJNZ R3, Here
RET

ECE473/573 16
Microprocessor System Design, Dr. Shiue
Nested Loop
Ex5: Find the time delay for the following subroutine

Delay: MOV R2, #200


Again: MOV R3, #250
Here: NOP
NOP
DJNZ R3, Here
DJNZ R2, Again
RET

ECE473/573 17
Microprocessor System Design, Dr. Shiue

S-ar putea să vă placă și