;
;      
;              preparing8ul.txt
;
start:
;     ldi tmp3,1
;     out gtccr,tmp3 ;  
;     ldi tmp3,4 ; tmp3=4
;     out tccr0b,tmp3 ;     1:256
     ldi tmp3,1
     out tccr0b,tmp3 ;    
  ;--------------------------------------------------------------------
     ldi pstfi,0 ;   
  ;--------------------------------------------------------------------
wait_prep:
     sbrs flags,kadr_end ;    
     rjmp wait_prep
 rereco:     
     clr pokan
     inc pokan ;    
     ldi xl,amochan ;  (xl=cntpp!)
     ldwi y,cnt_frame_0 ;     
  rereco2:
     ld tmp1,y
     dec tmp1
     st y,tmp1
     tst tmp1
    brbs SREG_Z,rereco3 ;    -    
  simple_out:
      adiw y,1 ;        
      lsl pokan ;    
     dec xl ; cntpp=cntpp-1
     tst xl
    brbc SREG_Z,rereco2 ;     
   cbr flags,(1<<kadr_end) ;   kadr_end   " "
  rjmp wait_prep ;    
  ;--------------------------------------------------
rereco3:
     adiw y,amochan ; Y+8 = next_Nl
     ld zl,y
     adiw y,amochan ; Y+8 = next_Nh
     ld zh,y
  pointr0:
       lpm tmp0,z+ ;    (   ) (z=z+1)
       lpm tmp1,z+ ;    (/= / ) (z=z+1)
       lpm tmp2,z+ ;     /  (z=z+1)
       lpm tmp3,z+ ;     /  (z=z+1)
     ; Z(DPTR)=  , index=next_Nh
  stripping:
      tst tmp1
      brbc SREG_Z,pstep ;  tmp1      
      rjmp selkom ;    
   pstep:         ;      
     sbiw z,2 ; z=z-2 , y=next_Nh
     st y,zh ;   next_Nh
     sbiw y,amochan ; Y=next_Nl
     st y,zl ;   next_Nl
     sbiw y,amochan ; Y=cnt_frame_N
     st y,tmp1 ;   cnt_frame_N 
     sbiw y,amochan ; Y=tmp_lev_N
     st y,tmp0 ;   tmp_lev_N
     adiw y,amochan ; Y=cnt_frame_N
    rjmp simple_out ;     
 selkom:
    tst tmp0
    brbc SREG_Z,callers ;     dr_call, dr_ret  dr_nop
  dr_jmp:
      mov zl,tmp2
      mov zh,tmp3 ;      Z(DPTR) 
    rjmp pointr0 ;       
 callers:
      mov temp,pokan ;    
      and temp,tmp0 ;    temp    .
     brbc SREG_Z,callers2 ;   callers2
  dr_nop:
      rjmp pointr0 ;  ""  (Z=  )
 callers2:
     and temp,pstfi ;    "  "
     brbs SREG_Z,dr_call ;   0 -   dr_call
            ;   1 -   dr_ret
  dr_ret:
     com temp
     and pstfi,temp ;   "  "
     adiw y,amochan ; Y=revs_Nl
     ld zl,y
     adiw y,amochan ; Y=revs_Nh
     ld zh,y ; Z   
     sbiw y,(amochan*2) ;    Y (y=next_Nh)
    rjmp pointr0 ;      Z
  dr_call:
      or pstfi,pokan ;   "  "
      adiw y,amochan ; Y=revs_Nl
      st y,zl
      adiw y,amochan ; Y=revs_Nh
      st y,zh ;    Z   revs_Nh:revs_Nl
      sbiw y,(amochan*2) ;    Y (y=next_Nh)
    rjmp dr_jmp ;    dr_jmp