Andy1845c
Active Member
Am am trying to get a firm grip on programming in Assembly. I can sort of modify some code, but I am trying to understand it well so I can write from scratch.
I have been running the code below in the MPLAB sim, and I can't figure out where we suddenly get 255 to put into Delay1 and count down from. Don't we have to put a number in W, then move it to where ever we want it? It just seems to pop in there out of thin air.
I also am fuzzy on the "f" after delay1 and delay2. As silly of a question as this probably is, can someone point me toward some info on it?
I have been running the code below in the MPLAB sim, and I can't figure out where we suddenly get 255 to put into Delay1 and count down from. Don't we have to put a number in W, then move it to where ever we want it? It just seems to pop in there out of thin air.
I also am fuzzy on the "f" after delay1 and delay2. As silly of a question as this probably is, can someone point me toward some info on it?
Code:
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay1 ; Define two file registers for the
Delay2 ; delay loop
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
bcf TRISC,0 ; make IO Pin B.0 an output
bcf STATUS,RP0 ; back to Register Page 0
MainLoop:
bsf PORTC,0 ; turn on LED C0
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.
bcf PORTC,0 ; Turn off LED C0
OffDelayLoop:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...
end