count1 equ 0x20 ; allocating 4 memory spaces to 4 variables, I think we only need 3
counta equ 0x21
; countx equ 0x22
countb equ 0x23
org 0
goto Start
Start
nop
nop ; Init registers
nop
call Transit
nop
nop
nop
Transit
movlw d'50'
movwf count1 ; Initialize count1 "main loop", set to 50
d1 ; moved this line down one
movwf counta ; first time initialize counta to 50 then it follows count1 as it decrements
d2
call sub1
decfsz counta ; decrement counta from last value of count1 (initially 50) down to zero
goto d2 ; do sub1 until counta gets to zero
movlw d'51' ; move 51 to w
subwf count1,w ; Set w= 51-count1 ,subtract count1 from 51 and place in w
; movlw countx ; don't believe we need this variable here now
movwf countb ; move content of w (ie: 51-count1) into countb
d3
call sub2
decfsz countb ; decrement countb from (51-count1) down to zero
goto d3 ; do sub2 until countb is zero
decfsz count1 ; we need to jump over two lines (ie: movlw, goto d1) if count1=zero <-------
movlw count1 ;read and move content of count1 to w to be placed in counta on top
goto d1 ; keep doing the main loop until count1= zero, each time the highest value for counta is the new count1
nop
nop
return
sub1
nop
nop
return
sub2
nop
nop
return
end