Shop OBEX P1 Docs P2 Docs Learn Events
SX/B Help - Passing string to a subroutine — Parallax Forums

SX/B Help - Passing string to a subroutine

John CoutureJohn Couture Posts: 370
edited 2005-09-06 04:13 in General Discussion
I'm trying to display a string using a subroutine.· Something like the following.· Complete code in attachment.· The problem is that I can't seem to be able to pass the string name as a parameter.· When I hardcode·the string name in the subroutine, it works ok.· Thus, it must be some kind of syntax error that I'm introducing that is preventing the passing of the string address.· There's something about that __PARAM1 and the @ symbol that I am not understanding.

DISPLAY SUB 1

Msg1:
··· Data "This is a string",0
Msg2:
··· Data "Another string ",0

start:
····DISPLAY Msg1
··· PAUSE 255
····DISPLAY Msg2
··· PAUSE 255
··· goto start

'
' page 1 subroutine section
'
DISPLAY:
·· dpos = 0
·· goto disp6
disp5:
·· dcol = 64
·· goto disp7
disp6:
·· dcol = 0
disp7:
·· POSCUR dcol
·· read __PARAM1+dpos,dbyte
·· if dbyte=0 then disp9
·· LCDOUT dbyte
·· dcol = dcol + 1
·· dpos = dpos + 1
·· if dcol = 72 then disp6
·· if dcol = 8 then disp5
·· goto disp7
disp9:
·return

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-05 11:44
    Have you downloaded the latest version of SX/B? If not, please do and then look in the examples for READ. One of the improvements made is the handling of strings and with 1.42 you can pass the name of a string (z-string stored in a DATA table) or pass as string directly.

    You could actually simplyify the TX_STR subroutine so that it only sends whole strings like this:

    TX_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
    ··· TX_BYTE temp5······························ ' send character
    ··· INC temp3·································· ' point to next character
    ··· temp4 = temp4 + Z·························· ' update base on overflow
    · LOOP
    · RETURN

    Another thing I noticed is that you're manually creating a jump table -- this is no longer required with SX/B is you use the SUB declaration.· By using SUB, the jump table is created for you and the compiler will check your code for the proper number of parameters.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 9/5/2005 11:47:19 AM GMT
  • John CoutureJohn Couture Posts: 370
    edited 2005-09-05 22:39
    Jon,

    Thank you! I'm working on it now. My apologies for not downloading the 1.42 version earlier. Good example in the attachment.

    Now that's dedication! You answered the email at 3:44am! Are you on the East Coast or something? (grin)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-06 00:07
    Central Time Zone (Dallas, TX). Funny, I don't remember getting up that early, but yesteday was a big movie day (my other love), so I may have....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • John CoutureJohn Couture Posts: 370
    edited 2005-09-06 02:32
    Jon,

    In the READ2.SXB listing above, the TX_STR subroutine:

    1) The comments above TX_STR show a usage of up to THREE parameters (one of them is an either or param), yet the subroutine assigns PARAM1 through PARAM4 to variables. What happened to the fourth parameter in the USE documentation?


    2) You use a "C" and a "Z" which seem to be aliases (ref online manual under "SX/B Aliases, SX Registers")
    C = Carry (Status.0)
    Z = Zero (Status.2)

    If one assumes that PARAM2 is the count (as in how many characters to send out), then I don't understand the adding of a bit to this variable. Can you explain this one further. (Ref: line 150 and line 160)

    3) It seems that if you are sending a string to a subroutine, the subroutine has to assign PARAM1 and PARAM2 to SOMETHING even if you want the subroutine to send the entire string. Am I correct?

    4) (grin) If you rewrite this example, would it be easier to read if you used stemp1=param1, stemp2=param2 etc instead of temp3=param1, temp4=param2, if it is a full moon temp5=Mickey Mantle, temp6=the catcher .... Who's on first base again?

    This SX sure is a fun chip! Thank you for all of the info that you make available to us.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-06 04:13
    1) Strings count as two parameters: base and offset (this is mentioned in the help file toward the end of READ; the section concerning strings)
    2) __PARAM1 is the offset, __PARAM2 is the base -- the address is sent "Little Endian" (low byte, high byte)
    3) Yes, again, strings take two parameters (which point to the starting location in memory of the string)
    4) It works now ... why rewrite it? (other than simplifying to eliminate substrings)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.