Shop OBEX P1 Docs P2 Docs Learn Events
Spin code execution details — Parallax Forums

Spin code execution details

NikopotomusNikopotomus Posts: 5
edited 2009-10-30 03:00 in Propeller 1
I have been looking and looking and can find no detailed description of how Spin code is actually executed. My understanding so far is that the Spin interpreter gets loaded into cog zero during boot-up. I'm interested in what happens when Spin code is run from other cogs. Does the actual execution occur in cog zero using main RAM? And if so are there any guidelines for determining execution times? I'm guessing that executing spin from a cog treats a spin command like a subroutine call to main RAM that executes on cog zero. Is that even close to what happens. Is there a detailed description anywhere?
Thanks
Joel roll.gif

Comments

  • ericballericball Posts: 774
    edited 2009-10-27 17:39
    The Propeller Tool compiles your SPIN code into SPIN bytecode (similar to how a Java compiler works). This is done to make the program compact since it's stored in HUB RAM. The SPIN interpreter is loaded into a cog. The interpeter fetches the bytecode from HUB RAM and executes the instruction. The bytecode instruction might be something simple like "push 0 onto the stack", or "pop the top two values off the stack, add them together, and push the result back onto the stack", or it might be something more complex like a subroutine call. When you use COGNEW to start a new SPIN interpreter, the new interpreter runs in a separate cog and doesn't interact directly other interpreter still running in cog 0.

    http://propeller.wikispaces.com/Spin+Byte+Code

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-27 18:43
    There is no "detailed description" other than what you'll find distributed throughout the Propeller Manual and datasheet.

    The bootloader essentially does a COGINIT (see the Manual for details) that forces a reinitialization of cog 0 using the Spin interpreter code stored in on-chip ROM. When you explicitly call COGNEW or COGINIT from a running cog, it also forces a reinitialization of the specified (or implied) cog using the Spin interpreter in ROM or using the assembly language routine that you specify. If you're starting a Spin routine, you also have to supply the address of an area in memory to use as the stack for the Spin routine(s). The Spin interpretive code all resides in the 32K hub memory. The cog's memory is completely filled with the Spin interpreter.

    When you start a Spin routine using COGINIT or COGNEW, the COGINIT or COGNEW returns immediately. It takes about 100us or so for the cog to be initialized and start executing the Spin code and this all happens in parallel with whatever the original cog is doing. If the new Spin routines exits, it causes the cog to stop. The COGINIT or COGNEW initializes the new cog's stack with a return address to a COGSTOP instruction which will effectively reset the cog that's executing it.
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-10-27 18:45
    Look in my signature for the Tools link and in that thread there will be a post linking to my Faster Spin Interpreter. That thread contains lots of info and links to what yo are looking for including Chip's published Interpreter and a complied listing of it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • NikopotomusNikopotomus Posts: 5
    edited 2009-10-28 05:53
    Hmmm.... Spin is compiled to bytecode.... That explains everything. Thank you.
Sign In or Register to comment.