Shop OBEX P1 Docs P2 Docs Learn Events
Program Counter with Spin — Parallax Forums

Program Counter with Spin

CassLanCassLan Posts: 586
edited 2009-03-06 12:50 in Propeller 1
Hello,

Is there a way to provide a label or memory address to have the program jump too with spin?

I'd like to provide such a label or address in a DAT block then stored in a·variable. I'm gettig the feeling this is easily attainable in asm but I'd like to stick with spin for this if its possible.
I guess I'm looking for a GOTO <variable> command, does one exist?

Or could I use _label and JMP right in my spin code?

Thanks,

Rick

Post Edited (CassLan) : 3/6/2009 1:40:18 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-06 01:41
    There is no GOTO in Spin. The only thing close would be QUIT and NEXT for REPEAT loops and subroutine calls and RETURN statements

    If you want to provide some kind of action table, you could use a CASE statement and store the indices for the CASE statement in your DAT block.
  • jazzedjazzed Posts: 11,803
    edited 2009-03-06 01:49
    Do you want to call a method based on some index value? This can be done using OBJs. I'll dig it for you if you like ... or someone else can.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-03-06 02:03
    Mike Green said...
    There is no GOTO in Spin.
    Hadn't noticed that, having written no Spin.· Wow.· That's reason enough to use PASM exclusively.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • CassLanCassLan Posts: 586
    edited 2009-03-06 03:59
    Thank you Mike and Steve, I know what your saying about using CASE. I can do it that way, I was just wondering if there was another way.

    Thanks,

    Rick
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-06 05:20
    Carl,
    Does that make you a Luddite? Seriously, the whole discussion of GOTOs vs. no GOTOs was talked to death many many years ago. There are major advantages in code clarity in avoiding or at least minimizing the use of explicit GOTOs (as opposed to the implicit ones that are used to construct the various control structures like IF/THEN, REPEAT, CASE, etc.). A friend challenged me once to write a multi-tasking operating system without GOTOs. It wasn't as difficult as I thought and the discipline forced me to code much better than I might have otherwise.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-06 12:50
    Wouldn't it be possible to have an array with the adresses and simply call a cognew with one of these?
    After that you let the old cog stop. Of course your local variables will be lost, but you don't have to use local variables, do you?

    Would be an expensive goto in terms of runtime ... but should be possible.·
Sign In or Register to comment.