Shop OBEX P1 Docs P2 Docs Learn Events
asm and ram hub adress — Parallax Forums

asm and ram hub adress

Hello everyone,
I'm just starting to do some interesting things with the Propeller, so I have a silly question… I'd like to have a compiled assembly program in the RAM hub (which doesn't run) after initialization, and then have a cog load this code snippet from its memory address and execute it. This is simple with another MCU, but I don't know how to do it with the Propeller. I want to emphasize that I need to be able to launch it from its address (not a DAT spin block whose location I don't actually know…). Perhaps it's simple?

Thanks

PS: This is an automatic translation

Comments

  • JonnyMacJonnyMac Posts: 9,614
    edited 2026-01-26 16:54

    Perhaps it's simple?

    Yes. The @ symbol gives you the address of code in a DAT block (which lives in RAM and can be copied to one or more cogs).

    For example, here's a simple 50% duty-cycle flasher for a pin.

    dat 
    
                            org       0
    
    flashpin                mov       t1, par                       ' point to parameters
                            rdlong    t2, t1                        ' read pin
                            mov       pinmask, #1                   ' convert to mask
                            shl       pinmask, t2
                            or        dira, pinmask                 ' set to output
                            add       t1, #4
                            rdlong    delayticks, t1                ' get 1/2 cycle ticks
    
                            mov       t1, cnt
                            add       t1, delayticks
    
    loop                    or        outa, pinmask                 ' led pin high
                            waitcnt   t1, delayticks
                            andn      outa, pinmask                 ' led pin low
                            waitcnt   t1, delayticks
                            jmp       #loop
                                           ' 
    
    ' --------------------------------------------------------------------------------------------------
    
    pinmask                 res       1
    delayticks              res       1
    
    t1                      res       1                             ' work vars
    t2                      res       1
    t3                      res       1
    

    It needs two consecutive longs to provide the pin # and the half-cycle delay in ticks

    var 
    
      long  flasher
      long  ticks 
    

    Set the pin and delay and then start with cognew()

    pub main
    
      flasher := 26
      ticks   := CLK_FREQ >> 1
    
      cognew(@entry, @flasher)
    
      repeat
        waitcnt(0)
    

    This is in fact doing what you ask for:

    • Code defined in RAM (DAT sections are pre-initialized RAM)
    • @ provides the address of your code
    • cognew runs that code it a separate cog

    Just a note: If you want to know if your cog loaded and what cog it's in, this is the standard practice

      cog := cognew(@entry, @flasher) + 1
    

    If cognew() works then cog will be > 0 (evaluates as true), otherwise cog will be 0 (false). If you want to shutdown that cog

      cogstop(cog-1)
    

    You can use coginit() to load a specific cog.

  • Thanks. Yes, I know how to do that, but I want to be able to assign an address as a hexadecimal number, like when you start a Cog program in assembly... but in Spin. And above all, how do I put compiled assembly code at a specific address in the RAM hub?

  • RaymanRayman Posts: 15,965

    Guess you could first copy the assembly to that fixed place and then load the cog from there? Maybe that would work?

    That kind of goes against the grain for the Parallax Spin.

    FlexProp's spin has an absolute address operator that might make things easier. I know if from P2, but think works with P1 too...

  • Yes, I could copy to a specific location, but how? In Spin, I can't provide a hexadecimal address using Longmove? And how can I know the length of the compiled DAT file? And how can I avoid writing to the Spin code that's currently executing, since I don't know its address either?

  • RaymanRayman Posts: 15,965

    If you are using the Prop Tool, you can do info and see the memory map. Just stay a bit away from the very end because Spin uses that for stack space.

    I'd just copy 512 longs, that way can make sure it's all there...

    Longmove should work?

Sign In or Register to comment.