Shop OBEX P1 Docs P2 Docs Learn Events
PASM, what am I doing wrong? — Parallax Forums

PASM, what am I doing wrong?

Bobb FwedBobb Fwed Posts: 1,119
edited 2009-02-02 23:32 in Propeller 1
I have this code, when I run as is, I get a blank output on the PST (the CR works fine, but no number output).
CON
  _CLKMODE      = XTAL1' + PLL16X                     ' 80MHz clock (10MHz for frequency read, 40MHz for 9600 serial baud, 80MHz for shiftout and RFID read)
  _XINFREQ      = 5_000_000                          ' 5MHz Crystal

OBJ

  DEBUG  : "FullDuplexSerial"                        ' for debugging

VAR

  LONG retblock'[noparse][[/noparse]20]

PUB Main

  DEBUG.start(31, 30, 0, 57600)
  waitcnt(clkfreq / 2 + cnt)  
  DEBUG.tx($0D)
                      
  cognew(@math, @retblock)

  waitcnt(clkfreq / 2 + cnt)
  DEBUG.dec(retblock)

DAT

                        ORG 0
math
                        MOV     par1, #30
                        MOV     par2, #2
                        CALL    #divide               
                        JMP     #end

times10                 MOV     par2, par1      ' make copy
                        SHL     par2, #2        ' times 4
                        ADD     par1, par2      ' plus 1 (times 5)
                        ADD     par1, par1      ' times 2 (times 10)
                        MOV     ret_val, par1   ' move to return
        times10_ret     RET

divide                  SHL     par2, #15       ' get divisor into y[noparse][[/noparse]30..15]
                        MOV     idx, #16        ' ready for 16 quotient bits
        :loop           CMPSUB  par1, par2 WC   ' if y =< x then subtract it, set C
                        RCL     par1, #1        ' rotate c into quotient, shift dividend
                        DJNZ    idx, #:loop     ' loop until done
                        MOV     ret_val, par1   ' move to return
        divide_ret      RET

end
                        WRLONG  ret_val, PAR

par1                    LONG 0
par2                    LONG 0  
ret_val                 LONG 0
idx                     LONG 0   
                        FIT 496



But if I comment out the PASM "function" I am not using (times10 or divide), each chunk of code works just fine. How are they conflicting with each other?

Here PASM code that works:
math
                        MOV     par1, #30
                        MOV     par2, #2
                        CALL    #divide               
                        JMP     #end

divide                  SHL     par2, #15       ' get divisor into y[noparse][[/noparse]30..15]
                        MOV     idx, #16        ' ready for 16 quotient bits
        :loop           CMPSUB  par1, par2 WC   ' if y =< x then subtract it, set C
                        RCL     par1, #1        ' rotate c into quotient, shift dividend
                        DJNZ    idx, #:loop     ' loop until done
                        MOV     ret_val, par1   ' move to return
        divide_ret      RET

end
                        WRLONG  ret_val, PAR


OR
math
                        MOV     par1, #30
                        MOV     par2, #2
                        CALL    #times10               
                        JMP     #end

times10                 MOV     par2, par1      ' make copy
                        SHL     par2, #2        ' times 4
                        ADD     par1, par2      ' plus 1 (times 5)
                        ADD     par1, par1      ' times 2 (times 10)
                        MOV     ret_val, par1   ' move to return
        times10_ret     RET

end
                        WRLONG  ret_val, PAR


All I did was removed the unused code.

Comments

  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-02-02 23:32
    Are they conflicting? This may be a red herring, but neither your ASM code nor your main SPIN code have anything to keep them going once they finish. In the ASM code, you should have a

    self JMP #self

    or something along those lines at the end of the code, and have an infinite repeat loop at the end of the PASM. It may just be that FullDuplexSerial doesn't have time to send the output before the prop goes off into never never land.

    Could that be it? I'm still pretty new at this myself, so I may be way off here. [noparse]:)[/noparse]

    You could also modify your PASM code to write a non-zero value in the mem location after the ret_val, and use that to indicate that the PASM prop has finished. Then you'd actually know you got an answer, and your SPIN code could just repeat until that status value was non zero, then read out the answer, instead of waiting for a 1/2 sec.· (EDIT - I'm guessing, since you're writing ASM, that you already know this.)

    Jason
Sign In or Register to comment.