Shop OBEX P1 Docs P2 Docs Learn Events
Passing Addresses/Labels to Subroutines, Trouble with Read using an index and a — Parallax Forums

Passing Addresses/Labels to Subroutines, Trouble with Read using an index and a

YendorYendor Posts: 288
edited 2006-09-20 20:18 in General Discussion
Hi,

I have a few·questions on the SX/B.

1.· Is this the right way to pass an address that's defined in a label?
Main:
·· Pntr =·DefinedLabel
·· Subroutine @Pntr
·· END

Subroutine:
·Pntr = __WParam12
·READ Pntr, myvalue··················· ' get data and put in myvalue
·' do other stuff.
Return


2.· I'm having trouble using the index with read.· For example, the following gives a syntax error on the +

·Main:
·· ' main code here
·· Pntr =·DefinedLabel
···READ Pntr + 1, myvalue··················· ' get number of notes
END

3.· Is it true that in SX/B,·that we can't (yet)·compound math statements?
·· for example, the following code fails.

FOR idx = 0 TO·myvalue * 2 - 1

I would need to·split this up into the following, using the math order of operations, correct?

myvalue = myvalue * 2
myvalue = myvalue - 1
FOR idx = 0 TO myvalue


4.· Finally, we can only send a single byte using serout, correct?· For example, some of Jon's code from a project I'm trying to convert from BS2 to SX/B has an array called midi, and he's able to do the following:

····· SEROUT MidiOut, MidiBaud,·[noparse][[/noparse]cmd, STR midi\(notes * 2)]
So, I would basically need to break down the above commands into bytes, and send each one individually using the SEROUT command?

Thanks!

Rodney

Comments

  • BeanBean Posts: 8,129
    edited 2006-09-19 21:45
    1. Your very close:
    [indent]Main:
       Subroutine DefinedLabel
       END
     
    Subroutine:
     Pntr = __WParam12
     READ Pntr, myvalue                    ' get data and put in myvalue
     ' do other stuff.
    Return
    [/indent]
    
    


    2. You can't use index with word variables. Simple increament the word variable. Or use the new READINC instruction.

    3. It's true. SX/B has limited storage for math.

    4. This is true also, for the same reason.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • YendorYendor Posts: 288
    edited 2006-09-20 11:51
    Thanks again Bean!·· Your support is awesome!

    I need a bit more help, though...

    1.· Are all variables global in scope?· So, even though it's poor programming practice, we really don't have to pass the variable name to the subroutine, right?·· For example, in your code clarification, can we just do the following?
    Main: 
    Subroutine 
    END 
    
    Subroutine: 
    READ DefinedLabel, myvalue ' get data and put in myvalue 
    ' do other stuff. 
    Return
    
    I also forgot to declare the sub as two bytes for sending a word which was causing me some minor grief- that's how I got onto the @ bandwagon in the first place, just trying to compile - doh!

    2.· I'm still a little confused on this.· Is the word variable you're referring to, is the address (Pntr in my case)?
    In the format definition·for the Read function (in the SX/B help file), isn't base a word type?·
    The code snippit from there seems to be similar to what I had:
    READ Pattern + idx, RB  ' Pattern is an Address
    
    Otherwise the Reading statement will do.· I forgot about the update.

    2a.· Also, to sneak in another question,·is there a way can mix bytes and words in the same data statement?·
    as in:· DATA:· Byte, Byte, Word, Byte
    I guess I just would need to break it into byte sizes and convert to a word at the appropriate index, correct?

    3 & 4· I guess that give us something to look forward to!

    Also, for some strange reason, I find compiler design fascinating.· Since you're the first that I've conversed with, and are quite helpful, I was curious if you can share with us your favorite compiler design reference texts, such as Green or Red Dragon Books by Aho, or others.·


    Again, thanks!

    Rodney
  • BeanBean Posts: 8,129
    edited 2006-09-20 12:47
    1) Yes, that is perfectly legal. (at least in this state).

    2) A word variable can hold a label address, but they are not the same to the compiler. It handles each differently. When using a word variable it's just as easy to adjust it, instead of having to declare another variable to use as the offset. Also don't forget about the new READINC command, it will automatically adjust the variable for you.

    3) You can freely mix bytes and words in one DATA line, but if the word value is < 256 then you will have to add a ",0" for the MSB of the word value. This is easy to forget, causing loss of hair and sanity [noparse];)[/noparse] because all the data read after that record will be shifted by 1 byte.

    4) The compiler design was very much "seat of the pants". It was driven at first by my personal "wish list". Then driven by Parallax's requirements. And now by the user base (as it should be). It is written in Delphi and is·strongly object oriented.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • YendorYendor Posts: 288
    edited 2006-09-20 20:18
    Thanks again Bean!

    Reading it is!

    I'm glad to find out the reason for my balding! Sorry for the DATA/WDATA question. I see now that it's explaned in the SX/B help file, after rereading.

    I read in another post that you were writing it in Delphi. Just trying to get some insite on brilliance as it's nicely done, as it's indeed a complex process. Not just for parsing the grammar, but getting the SX assembly to work as intended, as well! I guess I don't have to tell you that!

    Thanks again!

    Rodney
Sign In or Register to comment.