Shop OBEX P1 Docs P2 Docs Learn Events
Subroutine executes on one time — Parallax Forums

Subroutine executes on one time

aa200orionaa200orion Posts: 10
edited 2009-07-20 01:03 in General Discussion
I'm new to the BSSX world and it has been many years since I did any programming.· I'm trying to generate a data string that consists of a sync pulse, an 8-bit data field, an 11-bit data field, and a 3-bit suffix code.· I'm programming in stages to learn the SX/B language and become familiar with the BSSX.· The code I have written is attached.· The part I'm having trouble with is the FOR loop in the NIDEK_CODE subroutine.· It only exceutes once.· Any help will be appreciated.

Jimmy

Comments

  • ZootZoot Posts: 2,227
    edited 2009-07-19 17:27
    Your logic is flawed. You JUMP while in your for/next code, which is a subroutine. Since the the two jump locations are also subs, when they finish, the RETURN is really for the FIRST sub called -- NIDEK. You should probably change the the jumps to GOSUB (or CALL @ in ASM), e.g.

    SUB    NIDEK_CODE
        HIGH LED    
        ASM    CLC
        ENDASM
        
        FOR idx =1 to 9
            ASM    
                RR NIDEKCODE
                JC    @GoSu_OutOne
                ' JMP    OUTZERO  now not needed as outzero follows
                
            ENDASM
    
    
                 GoSu_OutZero:
                    OUTZERO
                    GOTO FNdone
    
                 GoSu_OutOne:
                    OUTONE
    
             
              FNdone:
    
        NEXT
    
    ENDSUB
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • PJMontyPJMonty Posts: 983
    edited 2009-07-19 17:40
    Jimmy,

    A "jmp" is simply a "GOTO", and you aren't allowed to "jmp" or "GOTO" from one routine into the middle on another routine - unless you want your program to crash. Zoot's approach is correct except that instead of saying you should "probably" change the jumps to GOSUBs, he should have said you need to change your jumps to GOSUBs.

    Thanks,
    PeterM
  • aa200orionaa200orion Posts: 10
    edited 2009-07-20 01:03
    Thanks guys.· Another day when I learn something.



    Jimmy
Sign In or Register to comment.