Shop OBEX P1 Docs P2 Docs Learn Events
REP seems to not allow debug to operate as an instruction — Parallax Forums

REP seems to not allow debug to operate as an instruction

It seems that debug is ignored if used in REP instruction. See attached code. I wonder why?
Regards
Bob (WRD)

Comments

  • dnalordnalor Posts: 222
    edited 2021-08-25 19:37

    I didn't look at the code, but debug is an interrupt and interrupts will be ignored during REP looping. You can read this in the google document https://docs.google.com/document/d/1gn6oaT5Ib7CytvlZHacmrSbVBJsD9t_-kmvjd7nUR6o in chapter 'INSTRUCTION REPEATING'.

  • RaymanRayman Posts: 13,900
    edited 2021-08-25 19:40

    Is this debug an interrupt? I think it might be a jump to subroutine somewhere and then a jump back...
    Either way, it won't work with REP...

    The actual behavior does not appear documented anywhere, but it was discussed in this forum somewhere a while ago...

  • JonnyMacJonnyMac Posts: 8,929
    edited 2021-08-25 20:52

    The REP construct is very sensitive to loop disturbances. For example, you can't use CALL or any kind of JMP in a REP loop which is likely what's happening with DEBUG.

    Reminder: You can drop PASM2 code into a Spin2 method which means you don't have to launch an extra cog. I find this incredibly valuable for learning. For example:

    pub test_crcbit(p_src, len) : crc | b, n
    
      org
                    drvl      #LED1                                 ' P56 led on (use drvh for Edge)
    
                    debug("before CRCBIT ", ubin_byte(crc))
    
    .calc           rdbyte    b, p_src
                    add       p_src, #1                 
    
                    mov       n, #8
    .loop           shr       b, #1                         wc 
                    crcbit    crc, #$8C
    
                    debug("after CRCBIT  ", ubin_byte(crc))     
    
                    djnz      n, #.loop
                    djnz      len, #.calc
    
                    drvh      #LED1 
      end
    

    This code gives the same result as my CRC8 method shared in another thread -- it just takes more cycles for the same packet.

  • evanhevanh Posts: 15,192
    edited 2021-08-25 22:57

    Dnalor is correct for Pnut/PropTool. REP puts a hold on interrupts, and debug is highest level IRQ in the prop2 under Pnut solution. So debug won't respond until the REP is completed. The REP instruction is built this way to prevent unexpected branching.

    Rayman is correct for FlexSpin/C/Basic. There, debug will possibly create a bug because a branch instruction cancels the REP for good. Branching out of a REP is legal, but you need to account for it terminating the REP.

Sign In or Register to comment.