Shop OBEX P1 Docs P2 Docs Learn Events
stupid question — Parallax Forums

stupid question

Lee MarshallLee Marshall Posts: 106
edited 2007-08-03 16:45 in Propeller 1
hi, i just got my first propeller chip, and have finally got it to work(made programmer out of breadboard).
i am curious about the cognew/init instructions.
when starting a cog with the address of asm code(instead of spin subroutine), you can pass a parameter address, not a stack pointer. where does the cog put its return addresses??

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Z80 Rocks!

In a world without walls and fences, who needs windows and gates?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-02 04:56
    There is no return address ... The cog doesn't return. You're actually starting up another computer with the assembly program you provide. The COGNEW/COGINIT call does return, but it's the original computer (processor / cog) that does the returning after the new one is started.
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-08-02 04:59
    no, i mean if the program inside the cog calls a subroutine, where is the return address pushed to?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Z80 Rocks!

    In a world without walls and fences, who needs windows and gates?
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-08-02 05:17
    ah, i see now. would i be right in saying that when a program is written in asm, it doesnt utilise a call stack, instead, the host machine(computer running propeller tool) replaces RET instructions with JMP instructions, where the original address at which the call took place is the location which is jumped to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Z80 Rocks!

    In a world without walls and fences, who needs windows and gates?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-02 05:31
    There really isn't a RET instruction and the "CALL" instruction is really a JMPRET. The CALL and RET are really macro-like constructions to make calling subroutines more intuitive. If you write "CALL <foobar>", what you get is "JMPRET <foobar>_ret,#<foobar>". If you write "RET", you get a "JMP #0". For that matter, a "JMP #0" is really a "JMPRET 0,#0 nr".

    Anyway, there isn't a call stack. It's possible to emulate one with fairly low overhead. The "Large Memory Model" developed by Bill Henning has one version with a call stack in cog memory that would probably involve 5-6 extra instructions for the call and 3-4 for the return.
  • ericballericball Posts: 774
    edited 2007-08-02 19:06
    And just in case you weren't aware; ASM code can't call a SPIN subroutine (directly at least*).

    When you COGINIT/COGNEW to ASM, that ASM code is executing on separate processor (COG) with it's own 496x32 words of local RAM.· It can interact with the outside world via the 32 I/O pins (shared access) or the 32K of shared (HUB) RAM & locks.· Similarly, the SPIN code is actually an interpretter running on it's own processor, reading code from the shared RAM.· SPIN code can access SPIN subroutines because it's all sitting in shared RAM.

    Now, if you're talking about subroutines written in ASM (and loaded with the rest of the code in local RAM), then I recommend you look at the JMPRET instruction.··· There has been some discussion of dynamically loadable (and relocatable) subroutines in the forum, but I don't think anyone has implemented anything yet.

    * A SPIN subroutine could be triggered by ASM code through some kind of shared RAM/lock handshake.
    ·
  • hinvhinv Posts: 1,253
    edited 2007-08-03 02:37
    Now that wasn't a stupid question, in fact, it is a bit beyond me as I have not done assembly yet.

    As a former Z80 fan, have you found that the Propeller Whirs better than the Z80 Rocks?
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-08-03 07:15
    it certainly does, the things that seem to be missing(IMHO) are hardware stacks for asm code, and some kind of UART.

    thanks for all ur help, ppl.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Z80 Rocks!

    In a world without walls and fences, who needs windows and gates?
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-08-03 08:35
    Hello Mr. Crowley,

    with the propeller almost EVERYTHING can be done by a cog

    there are a lot of code-parts a little bit like "drivers" for
    a serial connection with 115kBAUD

    and if you would like to have 5 DIFFERENT serial connections
    you just start up 5 cogs doing all the details needed for a FULL-DUPLEX serial receiving/transmitting connection everyone at 115kBAUD !

    or 3 DIFFERENT SPI-buses or 4 I2C-buses whatever you like
    only limited by the number of 8 cogs inside one Propeller-chip

    just take a look through the demofiles and the object-eschange download section

    so to say "the propeller spins !"

    greetings
    Stefan
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-08-03 08:56
    ur right i guess, but why didnt they include asm call stacks, was it simply because they had no space left in the chip?
    burger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gifburger.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Propeller is the best micro!

    srry if im sound a little unprofessional sometimes, im 15.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-03 13:36
    Stacks are complex to implement in hardware (therefore costly in chip area), particularly if you want them to function at high speed and have reasonable depth (like more than 8 levels). They're not necessary for most programming, particularly the sort of stuff that one would write for doing I/O or writing a Spin interpreter that has to fit in less than 512 instructions. There is a perfectly functional call/return mechanism in the Propeller instruction set. The only thing you don't get is recursion.

    If by "call stacks", you mean a general stack mechanism where both data and return addresses can be pushed/popped, that's a different animal (a completely different computer design).

    Spin does have a stack architecture with the stack implemented in the much larger HUB RAM.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-03 16:45
    Have you looked at CALL..RET? It is an assembly level subroutine mechanism that doesn't rely on call stack, it works for any type of subroutine call except recursive, and computer science 101 teaches that in most languages recursive routines should be rewritten as an iterative routine (the exception to the rule is stack based languages such as lisp and forth).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.