t47_strindex_var_read.pas 605 B

123456789101112131415161718192021
  1. program t47;
  2. (* readln (s[i]) with a VARIABLE index.
  3. The address of the one byte the reader must store into is off+i, and i is
  4. only known at run time, so the reader has to carry a computed address:
  5. ParseSub leaves it in DI and IoCall pushes DI instead of a constant
  6. off+boff. t45 covers the same path with a constant index, which folds into
  7. boff; the two differ in exactly where the address comes from. *)
  8. var
  9. g : string[8] ;
  10. i : integer ;
  11. begin
  12. g := '........' ;
  13. i := 3 ;
  14. readln (g[i]) ;
  15. writeln (g) ;
  16. i := 6 ;
  17. readln (g[i]) ;
  18. writeln (g) ;
  19. writeln (g[3], g[6])
  20. end.