t67_strparam.pas 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. program t67_strparam;
  2. { t67 -- a STRING VALUE parameter. CALC.INC:17 is
  3. procedure Center(S : AnyString);
  4. TP3 puts a value parameter's whole SIZE on the stack (TPSRC7 tstscal), so a
  5. string[20] parameter is 21 bytes: the caller copies <len><chars> into the
  6. callee's slot, with the length byte at the lowest address (BP+4). That is
  7. what makes it a VALUE: the callee has its own copy, and mutating S must not
  8. touch the caller's variable.
  9. The fixture proves both halves:
  10. - `Show (t)' then `writeln (t)' prints `hello' again, so S[1] := 'X'
  11. changed only the copy;
  12. - `Show ('world')' shows a LITERAL argument being copied too.
  13. A by-address implementation would print `Xello' after the first call.
  14. The bytes come from a DS-relative byte loop, not REP MOVSB: MOVS addresses
  15. through ES, and nothing here establishes ES = DS. }
  16. var
  17. t : string[20];
  18. procedure Show (S : string[20]);
  19. begin
  20. writeln (S);
  21. S[1] := 'X'
  22. end;
  23. begin
  24. t := 'hello';
  25. Show (t);
  26. writeln (t);
  27. Show ('world');
  28. writeln (t)
  29. end.