Professional Documents
Culture Documents
DELAY LOOPS
Branching :
Conditional:
BC
BNC YYYYY
BZ
BNZ
BN
BNN
BOV
;Branch if C = 0
Looping :
MOVLW 24
MOVWF 50
MOVLW 32
ADDWF 50
ADDWF 50
ADDWF 50
ADDWF 50
ADDWG 50
ADD 32 to WREG
DECFSZ.. for
#include<P18F452.INC>
LOOPING
ORG 0
MOVLW 5H
#include<P18
MOVWF 50H
CLRF WREG
F452.INC>
ABOVE ADDLW 10H
DECFSZ 50H, F
ORG 0
GOTO ABOVE
MOVLW MOVWF 20H
5H
MOVWF
Nested Loop
NESTED LOOP
; SUBROUTINE
ORG 80H
DELAY1
LOOP..
;Main program
ORG 50
MOVWF 21H
L2
MOVWF 22H
L1
NOP
MOVLW 5H
NOP
movwf 00h
DECF 22H
movlw 10h
BNZ L1
AGAIN
addlw 25h
COMF PORTC
DECF 21H
BNZ L2
instruction
GOTO.
2M memory.
of the target
location.
As the Is
lsbitissufficient?..........
always 0 (Even address
GOTO
BRA .
2 byte instruction
BRA .
BRA
CALL instruction.
repetition.
4 Byte instruction.
(Similar to
GOTO : LSB =
0).
CALL instruction.
first instruction of
the subroutine.
instruction of all
Stack .
LIFO Memory.
Stack Pointer
location
SP+1)
Stack
. data.
Hence,
location
0 is not
availableTop
for the
Thus
we have only 31 locations available for the
As
the
data
is
pushed
into
the
stack,
data storage in stack.
PIC Stack 31 21
PUSH POP.
PC is
stored to stack, SP is
POP.
RCALL . (Relative
2 Byte instruction (Call is 4 Byte
CALL)
instruction)
CALL.
CALL Vs RCALL
CALL Vs RCALL
62 + 2 *00F = 80
PIPELINING
instruction.
(Number of
4/4 = 1 MHz;
Branch penalty
Branch penalty
right below
Branch penalty
only
one
Instruction execution
For
a PIC18 system of 16 MHz, find how long
time
it takes to execute each of the following
instructions:
(a)
MOVLW Ox55
Inst.
Cycles
1
(b)
DECF MYREG
1x0.25 s = 0.25s
(c)
MOVWF
1x0.25 s = 0.25s
(d)
ADDLW
1x0.25 s = 0.25 s
(e)
NOP
1x0.25 s = 0.25 s
(f)
GO TO
2x0.25 s =
(g)
CALL
2 x0.25 s = 0.5 s
Instruction
(h)
BNZ
2/1
Time to
execute
1x0.25 s = 0.25 s
(0.5 s
Taken, 0.25 s if it
falls through.)
0.5 s
0.5 /
0.25 s
CYC
LES
MOVLW
FF
MOVWF
20H
frequency is 16 MHz:
TOP
NOP
NOP
NOP
DECF 20H,F
BNZ
2 /1
TOP
RETURN
Time delay of
[( 255x6)+ 1 +1 + 11] 0.25 s = 383.25
s. As the last BNZ takes only 1 cycle, 383 s is the