Shop OBEX P1 Docs P2 Docs Learn Events
Simultaneous Global and Local Variable References — Parallax Forums

Simultaneous Global and Local Variable References

pjvpjv Posts: 1,903
edited 2010-02-08 02:39 in Propeller 1
Hi All;

In assembler I wish to have some local variables identified by the :VarName convention, but also access the same variable with a different but Global name. When I try to double define it, the Global of course limits the range of the Local, and defeats the intent

Is there a trick to make·this be possible?

Many thanks,

Cheers,

Peter (pjv)
·

Comments

  • BradCBradC Posts: 2,601
    edited 2010-02-08 00:08
    Not really, no. If you are defining a global at that address, why would you also want a local ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life may be "too short", but it's the longest thing we ever do.
  • VIRANDVIRAND Posts: 656
    edited 2010-02-08 00:34
    Name an unused HUBRAM address as a CONstant and use LONG[noparse][[/noparse]NAME]?
    That method is so lost in left field it doesn't know the name of the game, but I use it when I need globals.
    You may be able to find unused addresses at 32000, or OFFSCREEN_BUFFER, or near STACK.
    In PASM:
       rdlong register, pname 'get value of LONG[noparse][[/noparse]NAME]
       wrong register2,pname 'change value of LONG[noparse][[/noparse]NAME]
    ---
    register1 long something
    register2 long somevalue
    pname    long NAME     'or is it @NAME?
    
    


    It is unfortunately hard to find addresses in DAT space, although they tend to be offset by 16 bytes if you do.
    I have a worse hack to do that with, by using a bizarre unusual value like $ABADF00D and searching
    the whole hub for it using a variable to count to its address. Very inefficient.

    Maybe not what you want. I'd wait for a better answer. Mine is awful.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I should be typing in Spin now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-02-08 01:38
    Did you try putting the :local label before the global one? That will only work for one variable, though. Most assemblers have an EQU pseudo-op for stuff like this.

    -Phil
  • pjvpjv Posts: 1,903
    edited 2010-02-08 02:05
    Thanks for the suggestions.

    @Brad... probably that I am lazy, and wanted to include a generic piece of code into several assembly cogs without going renaming the variables in each duplicate, yet still trying to access the routines individually.

    @VIRAND.... I'm messing with assembler here, so I'm not sure how your comments apply.

    @Phil.... I tried that, and as you say, ony a single variable is not enough. I was hoping that I could do some kind of equate in the constants section, but a label with a leading colon seems not permitted there.

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 2/8/2010 2:10:05 AM GMT
  • BradCBradC Posts: 2,601
    edited 2010-02-08 02:39
    Homespun has a very basic #define capability where you can define a symbol and use the contents of that to replace the symbol in the code. That's probably as close as you are going to get without moving to a full macro pre-processor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life may be "too short", but it's the longest thing we ever do.
Sign In or Register to comment.