A dynamic
string variable is defined as a 32-bit data item, which contains a
SUB MyProc(abc$)
! PUSH EBX
! MOV EBX, abc$ ; EBX is a pointer to the string handle
! MOV EBX, [EBX] ; EBX is now a pointer to string data
! MOV AL, [EBX] ; AL contains the 1st char of the string
' more code could go here
! POP EBX
END SUB
If you need to determine the current length of a dynamic string, there are two ways to do so. The end of string is always followed by a nul, CHR$(0), so it is possible to scan the string for the first occurrence. Of course, this will only work if there are no embedded nul bytes in the string data. An alternative method is to read the 32-bit Long-integer that immediately precedes the start of the string data, as the current length is always stored there.
PowerBASIC also calculates string literals in reverse order, in keeping with standard assembler operation. For example:
FUNCTION ab(x???) AS DWORD
! PUSH EBX
! MOV EBX, x???
! MOV DWORD PTR [EBX], "ABCD"
! POP EBX
END FUNCTION
The above code stores
the value &H41424344 in the DWORD
variable x, passed
DIM a AS STRING, x AS DWORD
CALL ab(x)
a = HEX$(x,8) ' a = "41424344"
a = PEEK$(VARPTR(x),4) ' a = "DCBA"
See Also
Parameters passed by reference or by copy
Accessing PowerBASIC variables by name