Shop OBEX P1 Docs P2 Docs Learn Events
Mixing SPIN and Assembly — Parallax Forums

Mixing SPIN and Assembly

william chanwilliam chan Posts: 1,326
edited 2008-02-17 09:01 in Propeller 1
1. Is there a tutorial or example where SPIN and Assembly is mixed together and both run in one cog?

2. Is it always recommended to run the 1st cog in SPIN?

Thanks.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-17 01:35
    1. You can't run spin and assembly in the same cog.

    2. Your program must always have a small amount spin to get started so the first cog will initially have o run spin but after that you can do what you like.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-17 05:09
    To expand on #1: The Spin interpreter (which is written in assembly) fills up the cog that's running Spin interpretive code.

    The bootloader assumes that the loaded program is in Spin and always starts up a Spin interpreter on the contents of the program. This can consist of a (roughly) 32 byte Spin program followed entirely by assembly language. Cogs can hold only 2K bytes of instructions and data, but can load overlays from main (hub) memory.
  • william chanwilliam chan Posts: 1,326
    edited 2008-02-17 05:59
    When you call COGNEW to start a new cog on an assembly code, does the new cog 1st assume that your code is SPIN code and load the SPIN interpreter into the new cog first?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-17 06:09
    No, when you start a new cog from spin you tell it whether to start in assembly or spin by the method you tell it to start with. Have a look in the manual to see the syntax for each case. Note that when you are starting a cog from assembly you can only start it in assembly, not spin.

    Well it is possible to start it in spin but only Chip knows how smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-17 06:28
    That's not quite true. Chip has posted the code necessary to start a Spin program from assembly. It's part of the SPI and I2C routines in FemtoBasic.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-17 06:32
    Doesn't that code just reset the chip or something similar? I'll have to have a look.
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-17 09:01
    Yes, do smile.gif

    There is only ONE COGNEW machine instruction, which loads any 512 LONGS of memory into a COG and enables that COG. That is a hardware feature!

    The bootstrap loader is activitated by this in the very begining! And it uses that feature to load the first SPIN interpreter. This is the code you can find in Mikes routines. Also have a loook how you switch the clock speed!

    To load a piece of memory and enable a COG is also possible from SPIN.

    There is another SPIN instruction, ALSO called COGNEW, which does something similar as the bootstrap loader, but parametrizes the new instance of the interpreter to run the appropriate subroutine. Remember it has a bug there, being able to run a routine from the same Object only!

    Post Edited (deSilva) : 2/17/2008 9:53:03 AM GMT
Sign In or Register to comment.