
PROGRAM Foo;
TYPE ASCIIZ = ARRAY[0..255] OF Char;
CONST Neil : String[4] = 'Neil';
VAR
  A : ASCIIZ;
  S : String;
  N : Word;

  FUNCTION PChar2Str(_pstr : ASCIIZ) : String;
  BEGIN
    {_pstr is a *copy* of the actual passed ASCIIZ,
     so we can mess around with it.  Start by making
     room for a length byte...}
    Move(_pstr[0], _pstr[1], 255);
    {set the length byte to 255}
    _pstr[0] := #255;
    {treat _pstr as a string and use Pos to locate
     the terminating #0}
    _pstr[0] := Char(Pos(#0, String(_pstr)));
    {if #0 not found, the string was 255 characters
     long (or more)}
    IF _pstr[0] = #0 THEN _pstr[0] := #255
    ELSE Dec(_pstr[0]);
    PChar2Str := String(_pstr);
  END;

  FUNCTION PChar2StrA(VAR _pstr : ASCIIZ) : String; Assembler;
  ASM
    CLD
    LES DI, _pstr
    MOV CX, 0FFh
    XOR AL, AL
    REPNZ SCASB
    MOV AX, 0FEh
    SUB AX, CX
    LES DI, @Result
    STOSB
    PUSH DS
    LDS SI, _pstr
    MOV CX, AX
    REP MOVSB
    POP DS
  END;

BEGIN
  FillChar(A, SizeOf(A), 0);
  S := PChar2StrA(A);
  WriteLn('"', S, '"');
  Move(Neil[1], A, 4);
  S := PChar2StrA(A);
  WriteLn('"', S, '"');
  FOR N := 0 TO 254 DO
    A[N] := Char(Ord('0') + ((N+1) MOD 10));
  S := PChar2StrA(A);
  WriteLn('"', S, '"');

END.

