Shop OBEX P1 Docs P2 Docs Learn Events
String format question — Parallax Forums

String format question

mynet43mynet43 Posts: 644
edited 2007-05-17 04:09 in Propeller 1
I'm trying to figure out the format of a string in a calling sequence.

e.g. disp.str(string("this is a string..."))

I know that the str routine will work with a zero terminated string.

I haven't been able to locate the string( ) routine.

I'd like to know the difference between a string in quotes in a calling sequence and one that uses a pointer to a zero terminated string.

Like this:
OOPS byte "Oops, cog start failed...",0

If I say disp.str(@OOPS), it works fine.
If I say disp.str("Oops, cog start failed..."), it doesn't work.

If you'll point me to the string( ) routine, I'm sure I can figure it out.

Thanks for your help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-17 03:24
    STRING is defined as a directive and described in the Propeller manual. Its syntax is that of a function. It takes a series of constant values including quoted strings and constant expressions which are treated as byte values. A zero byte is appended to the end and the value of the STRING directive is the address of the first byte of the series of byte values where they're stored at runtime.

    Another way to define a string constant is, as you've demonstrated, in a DAT section with a label. Also, as you've shown, you can't just pass a string constant longer than 4 bytes. The compiler will complain. If the string constant is 4 or fewer bytes, it is treated as a 32 bit numeric value with the first character as the least significant byte (bits 0-7), the second character as bits 8-15, the third character as bits 16-23, and the fourth character as bits 24-31. If there are fewer than 4 characters, the space is filled with zero bits. Note that this can't be passed to one of the string output routines like disp.str() which expects an address.
  • mynet43mynet43 Posts: 644
    edited 2007-05-17 04:09
    Thanks Mike!

    I searched through all the code but I missed it in the manual.

    That really helps. Maybe I can write a str( ) routine that uses string( ) only when it needs to...
Sign In or Register to comment.