Download presentation
Presentation is loading. Please wait.
1
Conditional Jumps and Time Delays
Source:
2
The simplest implementation of delay: the instruction “NOP”
Source:
3
Different Interpretations of “NOP”
4
A single-loop time delay
“DJNZ” can be used here.
5
Similar implementation
Flowchart Program code Similar implementation Fill_Acc: MOV A,#30 Decrement: DEC A JZ Empty JMP Decrement NOP Empty: INC B JMP Fill_Acc MOV R0, 0FFH DJNZ R0, $
6
A 2-loop time delay ; **** 2-loop time delay **** MOV R0, #5 loadR1:
MOV R1, #3 DJNZ R1, $ DJNZ R0, loadR1 RET The overall number of iterations = N0 × N1
7
A 3-loop time delay Exercise:
Write a 3-loop delay procedure based on this flowchart.
8
2-loop 1-loop = A (composite) 3-loop time delay
threeLoopDelay: MOV R2, #0AH loop: CALL twoLoopDelay DJNZ R2,loop RET ; loop time delay ---- twoLoopDelay: MOV R0, #0FFH loadR1: MOV R1, #0FFH DJNZ R1, $ DJNZ R0, loadR1 RET
9
Instructions for conditional branching
JC Rel JNC JZ JNZ JB Bit,Rel JNB JBC DJNZ Byte,Rel CJNE <dest-byte>,<src-byte>, Rel
10
JC & JNC JC JNC Function Jump if carry set Jump if carry not set
Description Branches to the specified address if the carry flag is set Branches to the specified address if the carry flag is cleared Syntax JC rel JNC rel Steps (PC) <- (PC) + 2 IF (C) = 1 THEN (PC)< - (PC) + rel (PC) <- (PC) + 2 IF (C) = 0 THEN (PC) <- (PC) + rel Machine code Example JC LABEL JNC LABEL
11
JZ & JNZ JZ JNZ Function jump if accumulator zero
jump if accumulator not zero Description transfers control to the specified address if the value in the accumulator is 0. Otherwise, the next instruction is executed. transfers control to the specified address if the value in the accumulator is not 0. If the accumulator has a value of 0, the next instruction is executed Syntax JZ rel JNZ rel Steps (PC) <- (PC) + 2 IF (A) = 1 THEN (PC)< - (PC) + rel (PC) <- (PC) + 2 IF (A) = 0 THEN (PC) <- (PC) + rel Machine code Example JZ LABEL JNZ LABEL
12
JB, JBC, & JNB JB JNB JBC Function Jump if Bit is set
Jump if Bit is not set Jump and clear bit if bit is set Description branches to the specified address if the value of the specified bit is 1 branches to the specified address if the value of the specified bit is 0 branches to the specified address and clear the specified bit if the value of the specified bit is 1 Syntax JB bit,rel JNB bit,rel JBC bit,rel Steps (PC) <- (PC) + 3 IF (bit-addr) = 1, (PC)< - (PC) + rel (PC) <- (PC) + 3 IF (bit-addr) = 0, (PC) <- (PC) + rel (PC) <- (PC) + 3 IF (bit-addr) = 1, (bit-addr) = 0 and (PC) <- (PC) + rel Machine code bit, rel bit, rel bit, rel Example JB P1.2,LABEL JNB P1.2,LABEL JBC ACC.3,LABEL
13
DJNZ DJNZ <byte>,<rel-addr> Function
Decrement and Jump if Not Zero Description DJNZ decrements the location indicated by 1, and branches to the address indicated by the second operand if the resulting value is not zero. Execution steps: (PC) <- (PC) + instructionSize (byte) <- (byte) - 1 IF (byte) <> 0 THEN (PC) <- (PC) + rel Syntax DJNZ Rn, rel (Rn = R0, R1, …, R7) DJNZ direct, rel (“direct” is a location in RAM) Steps (PC) <- (PC) + 2 (Rn) <- (Rn) - 1 IF (Rn) <> 0 THEN (PC) <- (PC) + rel (PC) <- (PC) + 3 (direct) <- (direct) - 1 IF (direct) <> 0 THEN (PC) <- (PC) + rel Machine code 11011rrr rel bit add, rel Example DJNZ R5,rel rel DJNZ 30H, rel rel
14
CJNE CJNE <dest-byte>,<src-byte>, rel Function
Compare and Jump if Not Equal Description CJNE compares the magnitudes of the first two operands and branches if their values are not equal. Execution steps: PC = PC + 3 IF (dest) <> (src), PC = PC + rel IF (dest) < (src), C = 1 ELSE C = 0 Syntax CJNE A,#immediate,rel CJNE #Ri,#immediate,rel CJNE Rn,#immediate,rel , where x = 0 or 1, n = 0, 1, 2, …, or 7. CJNE A,direct,rel (“direct” is a location in RAM) Step IF A <> immediate, PC = PC + rel IF A < immediate, C = 1 ELSE C = 0 IF A <> (direct), PC = PC + rel IF A < (direct), C = 1 ELSE C = 0 IF (Ri) <> immediate, PC = PC + rel IF (Ri) < immediate, C = 1 ELSE C = 0 IF Rn <> immediate, PC = PC + rel IF Rn < immediate, C = 1 ELSE C = 0 Machine code immediate, rel n immediate, rel 10111nnn immediate, rel direct, rel Example CJNE A,#8EH,LABEL CJNE @R1,#8EH,LABEL CJNE R4,#8EH,LABEL CJNE A,34H,LABEL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.