Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conditional Jumps and Time Delays

Similar presentations


Presentation on theme: "Conditional Jumps and Time Delays"— Presentation transcript:

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 MOV MOV R0, 0FFH DJNZ R0, $

6 A 2-loop time delay ; **** The 2-loop time delay **** MOV R0, #0FFH
loadR1: MOV R1, #0FFH DJNZ R1, $ DJNZ R0, loadR1 RET The overall number of iterations = N0 × N1

7 A 3-loop time delay Homework:
Write a 3-loop delay procedure based on this flowchart.

8 2-loop  1-loop = A 3-loop time delay
; *** The 3-loop time delay *** threeLoopDelay: MOV R2, #0AH loop: CALL twoLoopDelay DJNZ R2,loop RET ; ---- The 2-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 rel JZ rel JNZ rel JB bit,rel JNB bit,rel JBC bit,rel DJNZ byte,rel CJNE <dest-byte>,<src-byte>, rel

10 JC & JNC JC rel Function: jump if carry set Description: branches to the specified address if the carry flag is set JNC rel Function: jump if carry not set Description: 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 rel Function: jump if accumulator zero
Description: transfers control to the specified address if the value in the accumulator is 0. Otherwise, the next instruction is executed.  JNZ rel Function: jump if accumulator not zero Description: 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 bit,rel Function: Jump if Bit is set
Description: branches to the specified address if the value of the specified bit is 1.  JNB bit,rel Function: Jump if Bit is not set Description: branches to the specified address if the value of the specified bit is 0. JBC bit,rel Function: Jump and clear bit if bit is set Description: 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 Syntax DJNZ Rn, rel (Rn = R0, R1, …, R7) DJNZ direct, rel
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 PC = PC + 3 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


Download ppt "Conditional Jumps and Time Delays"

Similar presentations


Ads by Google