t49_strcmp_lit.pas 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. { t49_strcmp_lit: string comparison where one or both operands are a LITERAL.
  2. A string literal has no storage, and the .COM image carries no initialised
  3. data (globals are left to the loader's zero fill), so TP3 emits the literal
  4. inline in the CODE stream - a JMP over its bytes, then <len><chars> - and
  5. takes its address with the LEA that follows. So this pins PushStrAddr's
  6. inline path (the jump, the length byte, the address) as well as the compare
  7. itself, in both operand positions and with both operands literal.
  8. The empty literal '' is the length-0 case of that path, and it also drives
  9. cmpstr's JCXZ arm, where min(lenL,lenR) is 0 and the loop never runs. }
  10. program t49_strcmp_lit (input, output);
  11. var
  12. s : string[8];
  13. n : integer;
  14. begin
  15. s := 'abc';
  16. n := 0;
  17. if s = 'abc' then n := n + 1; { literal on the RIGHT }
  18. if s <> 'abc' then n := n + 2;
  19. if s < 'abd' then n := n + 4;
  20. if s > 'abb' then n := n + 8;
  21. if s <= 'abc' then n := n + 16;
  22. if s >= 'abc' then n := n + 32;
  23. writeln(n); { 61: =, <, >, <=, >= }
  24. n := 0; { literal on the LEFT }
  25. if 'abc' = s then n := n + 1;
  26. if 'abd' > s then n := n + 2;
  27. if 'abb' < s then n := n + 4;
  28. writeln(n); { 7 }
  29. n := 0; { BOTH operands literal. Note '' is the
  30. empty STRING while 'a' would be a CHAR,
  31. so only string literals may appear here
  32. (see t50 for the CHAR case). }
  33. if 'abc' = 'abc' then n := n + 1;
  34. if 'abc' <> 'abd' then n := n + 2;
  35. if '' < 'ab' then n := n + 4;
  36. if '' = '' then n := n + 8;
  37. writeln(n); { 15 }
  38. s := 'ab'; { and all four as VALUES }
  39. writeln(s < 'abc', ' ', s > 'abc', ' ',
  40. 'ab' < 'abc', ' ', '' < 'ab')
  41. end.