Shop OBEX P1 Docs P2 Docs Learn Events
Assembly routine question — Parallax Forums

Assembly routine question

PliersPliers Posts: 280
edited 2013-10-28 13:08 in Propeller 1
How do I compare the Exit_Pattern to the current Pattern and then exit the loop if they are equal ?

PUB ex01 cognew(@ex01A, 0)


 
DAT 
ORG 0
ex01A
MOV DIRA, My_out ' Output to I/O 16 thru 23 
loop

MOV OUTA,pattern
add pattern, #1
JMP #loop ' repeat loop

My_out long $00FF0000    'IO pins set
pattern long $0                   'Starting value
Exit_Pattern long $AA         ' Pattern to cause exit from loop


FIT 496

Comments

  • ChrisGaddChrisGadd Posts: 310
    edited 2013-10-28 08:38
    Use the compare instruction, write the zero flag if they're equal, repeat the loop until they are. However, I suspect the code still won't work like you're expecting. You're using pins 16 through 23 as your outputs, so you should be adding 00_01_00_00 to pattern every loop, and end_pattern should be 00_AA_00_00.
  • PliersPliers Posts: 280
    edited 2013-10-28 08:40
    Thanks for the hints.
  • PliersPliers Posts: 280
    edited 2013-10-28 08:55
    Working now. Thanks.

    Is this a good way to exit an assembly program?
    PUB ex01 cognew(@ex01A, 0)
     
    DAT 
    ORG 0
    ex01A
    MOV DIRA, My_out ' Output to I/O 16 thru 23 
    loop cmp pattern,Exit_pattern wz
     if_Z jmp #stop
    MOV OUTA,pattern
    add pattern, #1
    JMP #loop                       ' repeat loop
    
    stop nop                          ' exit ex01A 
    
    
    My_out long $00FF0000             'IO pins set
    pattern long $0                            'Starting value
    Exit_Pattern long $00AA0000      ' Pattern to cause exit from loop
    
    
    FIT 496
    
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-10-28 09:15
    ADD pattern, #1 does NOT work unless you intend for it to count to 65535 before it adds 1 to the visible LED status
    You would have to use ADD pattern, my_00010000


    Not having to declare every value over 511, you could use shl instead with a declared Constant
    The extra code space will be offset by not having any longs declared.
    If you want up to and including $AA on LED, could switch places for ADD and CMP , or use #$AA+1
    CON  pingroup = 16              ' start at P16
    
    PUB exitAA
    cognew(@ex01A, 0)
    
     
    DAT 
    ORG 0
    ex01A
            MOV t1,#$ff
            SHL t1,#pingroup
            MOV DIRA, t1            ' Output to I/O 16 thru 23
            MOV pattern,#0          ' or use #$aa if counting down
    loop
            MOV t1,pattern
            SHL t1,#pingroup
            MOV OUTA,t1
            ADD pattern, #1         '    { If LED count down from $AA to $01, you could save 2 longs
            CMP pattern, #$AA wz    ' count up to but not including $AA in LED Status  { 
    if_nz   JMP #loop               ' repeat loop   { by replacing the 3 longs with this: djnz pattern,#loop
    stop    JMP #stop               ' stop here
    pattern  res 1
    t1       res 1
    
    
    FIT 496
    
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-28 09:23
    No, it's not a good way. The cog will continue executing longs after the NOP and who knows what instructions will be in there and what they'll do. Best way (if your application can tolerate leaving the cog running) is to have a jump loop like:

    stop jmp #stop

    If power demands are important, then stop the cog like this:
    stop  cogid  t1
          cogstop  t1
    
    In this case, you'll have to be careful about output pins since they'll all be changed to inputs when the cog is stopped. If turning off the cog is important, but you need to leave the I/O pins as is, consider setting up a loop like this:
    stop  WAITPEQ  My_out,My_out
          JMP  #stop
    
    This essentially waits for an I/O pattern that will never exist, but there's a JMP just in case.
  • PliersPliers Posts: 280
    edited 2013-10-28 13:08
    Thanks for all the input.
    You guys are great.
Sign In or Register to comment.