SX/B - SubRoutine - Question on minimum # of parameters
John Kauffman
Posts: 653
(please delete same post with no subject line)
I am trying to understand the declaration and use of parameters in a section of code provided by Parallax in support of their serial display (part 27977).·The code works fine, I am not understanding how it works.
·
Question #1 regards a sub declaration’s MIN parameters
SX/B help states that in the sub declarations, the two arguments are the min and max number of parameters. If only one value is provded ten that is t emin and max. The code line of interest (follows, line 92) indicates that a minimum of two parameters must be sent when the sub is called.
LCD_STR······ SUB· 2············ ' send string to LCD
·
But when the sub is called in the program (follows, line 118) only one parameter is sent
LCD_STR " PARALLAX SX/B "
Question #2 – what does the parameter actually hold?
I lose the logic of the value in the parameter between the call of the sub and the use within the sub. When the sub is called the parameter is the string of characters to display. But within the sub the parameter seems to be an offset, which I would think is a number indicating where to start parsing the string to send individual bytes one at a time to the sub that actually displays them. And what value goes into temp4 since only one param was sent? I understand that the following code can pull characters from a data store (READ) but it is also used by the above GOSUB to display the literal string.
·
' Use: LCD_STR [noparse][[/noparse] string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
·
LCD_STR:·
temp3 = __PARAM1···· ' get string offset
temp4 = __PARAM2···· ' get string base
· DO
··· READ temp4 + temp3, temp5·· ' read a character
··· IF temp5 = 0 THEN EXIT····· ' if 0, string complete
··· LCD_OUT temp5·············· ' send the byte
··· INC temp3·················· ' point to next character
··· temp4 = temp4 + Z·········· ' update base on overflow
· LOOP
· RETURN
I am trying to understand the declaration and use of parameters in a section of code provided by Parallax in support of their serial display (part 27977).·The code works fine, I am not understanding how it works.
·
Question #1 regards a sub declaration’s MIN parameters
SX/B help states that in the sub declarations, the two arguments are the min and max number of parameters. If only one value is provded ten that is t emin and max. The code line of interest (follows, line 92) indicates that a minimum of two parameters must be sent when the sub is called.
LCD_STR······ SUB· 2············ ' send string to LCD
·
But when the sub is called in the program (follows, line 118) only one parameter is sent
LCD_STR " PARALLAX SX/B "
Question #2 – what does the parameter actually hold?
I lose the logic of the value in the parameter between the call of the sub and the use within the sub. When the sub is called the parameter is the string of characters to display. But within the sub the parameter seems to be an offset, which I would think is a number indicating where to start parsing the string to send individual bytes one at a time to the sub that actually displays them. And what value goes into temp4 since only one param was sent? I understand that the following code can pull characters from a data store (READ) but it is also used by the above GOSUB to display the literal string.
·
' Use: LCD_STR [noparse][[/noparse] string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
·
LCD_STR:·
temp3 = __PARAM1···· ' get string offset
temp4 = __PARAM2···· ' get string base
· DO
··· READ temp4 + temp3, temp5·· ' read a character
··· IF temp5 = 0 THEN EXIT····· ' if 0, string complete
··· LCD_OUT temp5·············· ' send the byte
··· INC temp3·················· ' point to next character
··· temp4 = temp4 + Z·········· ' update base on overflow
· LOOP
· RETURN
Comments
That subroutine code is now a bit dated; here's a similar subroutine from one of our (EFX-TEK) products that is a bit more elegant.
Robert
(e.g. May, June, July, etc.?)
Jon is right the NEXT version of SX/B is quite far away.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"
Benjamin Franklin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
Since it hasn't made it in the docs yet I do have a quick question about it. Will this always increment the pointer by 1 or will it increment the pointer by 2 if reading a word variable?
Any other useful commands that haven't made it into the docs yet?
Robert
READINC will adjust the pointer by how ever many bytes are read.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"
Benjamin Franklin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
See this post on READINC:
http://forums.parallax.com/showthread.php?p=638212
See also the link to my SX52 tricolored RTC clock (especially the SX/B code). It uses some 16x16 picture left scrolling subroutines that use READINC on WDATA statements. The first routine scrolls left·the smileyface from the right side to the center and then pauses for 2 seconds. The next routine scrolls left again off the screen and then clears it.
http://forums.parallax.com/showthread.php?p=649643
Post Edited (T&E Engineer) : 5/14/2007 3:13:34 PM GMT