Passing Addresses/Labels to Subroutines, Trouble with Read using an index and a
Yendor
Posts: 288
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?
2.· I'm having trouble using the index with read.· For example, the following gives a syntax error on the +
3.· Is it true that in SX/B,·that we can't (yet)·compound math statements?
·· for example, the following code fails.
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)]
Thanks!
Rodney
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
·· 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
·· ' 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
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
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.
·
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?
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:
2a.· Also, to sneak in another question,·is there a way can mix bytes and words in the same data statement?·
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!
Again, thanks!
Rodney
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.
·
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