Shop OBEX P1 Docs P2 Docs Learn Events
My first ASM dosent work — Parallax Forums

My first ASM dosent work

JCeeJCee Posts: 36
edited 2008-11-25 21:54 in Propeller 1
This is my first try at Assembly but it is not working out so well. I am trying to launch a new cog add two floating point numbers and display the result on the terminal. The following is the spin portion of the code and attached is the ASM routine.

OBJ  

    ss     : "floatstring"
    debug  : "fullduplexserial"

PUB Main

Num1 := 10.0
Num2 := 100.00
   
   Debug.start(31, 30, 0, 9600)
  
   repeat while Input <>= 13   'wait until enter is pressed in terminal
    Input := Debug.rx  
   debug.str(string("RUNNING"))
   debug.tx(13)

    cognew(@start,@Num1)    'start the addition in a new cog ~~~causes all the problems~~
    waitcnt(clkfreq +cnt)
   
    debug.str(ss.floattostring(num1))    'does not work with @
    debug.tx(13)
    debug.str(ss.floattostring(num2))    
    debug.tx(13)
    debug.str(ss.floattostring(Ans))
    debug.tx(13)
    debug.str(string("DONE"))



If i run the spin code without the cognew everything displays on the terminal as expected (other than the answer) but when I try to run the Spin with ASM code random characters are displayed on the terminal. It seems like my ASM code is causing problems with the fullduplexserial. I need help finding the bug.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-25 20:26
    I've just looked at how your assembly routine interacts with hub memory. What I notice is that there's no end to the routine. It just continues on into the constants. Basically, you need either
    hang     jmp   #hang
    

    or
         cogid      mem
         cogstop   mem
    

    after the WRLONG.
  • RaymanRayman Posts: 14,364
    edited 2008-11-25 20:52
    Santa strikes again!
  • JCeeJCee Posts: 36
    edited 2008-11-25 21:19
    Thanks Mike, works perfect now. I was under the impression that after a cog executes the last line of code it stops, i guess this is not the case?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-25 21:32
    In Spin, when the main method reaches the end, the executing cog stops. That's not true for assembly. Spin methods are called as subroutines and there's a dummy return address provided that returns to a COGSTOP. Assembly just starts at location zero and continues until it stops the cog or hangs in a loop.
  • JCeeJCee Posts: 36
    edited 2008-11-25 21:54
    Good to know
Sign In or Register to comment.