I have recieved the following script from Friedrich Schroeder, who asked me
to post it for him, since his access to the net, is very limited.

I also promised to receive letters to him about this artcle, so you can mail
me with your flames, comments, corrections, questions etc.

------------------------ Friedrich Scroeders article ----------------------

A new version of the HP-28S CHK program from Mr. Peraino.

This posting contains:

1) a correction of, what I believe is an error in the original CHK program.
2) the corrected program in m-code (runs 200 to 300 times faster).
3) a recusive CHECK program that use the m-code program.

1) The following program was written by Mr. Peraino.

  CHK [129]
  << RCLF HEX 16 STWS
     SWAP RCL ->STR DUP
     # 0h 1 ROT SIZE
     FOR j OVER j j SUB
       NUM R->B XOR RL
     NEXT ->STR 3 OVER
     SIZE 1 - SUB ROT
     STOF SWAP DROP
  >>

It is a good checksum-program, but I believe it has a flaw.
If you want to check a program with a binary integer in it, only the last
16 bit are included in the check. E.g. for the binary integer #D1234h only
#1234h is included.

This could be prevented by changing the CHK program to look like this:

  CHK [6A93]
  << RCLF STD HEX 64 STWS
     SWAP RCL ->STR 16 STWS DUP
     # 0h 1 ROT SIZE
     FOR j OVER j j SUB
       NUM R->B XOR RL
     NEXT ->STR 3 OVER
     SIZE 1 - SUB ROT
     STOF SWAP DROP
  >>

[ Editor's note - Indeed, the 16 STWS in my version of the program should
                  have said 64 STWS- it does on MY hp28. I must have typed
                  it in wrong when I put it on the archive. As for the
                  inclusion of STD, that was done long ago. Friedrich
                  must have had an old copy.  -Bob Peraino]

2) The m-code for the CHK program is a long hex-string and must be typed in
without spaces or newlines just a long string of hex-numbers. It can only be
used on a HP-28S ver 2.BB (sorry).

  TACHK [947A]
  "76C20EA9704B21179C
   B00167069C20080008
   F18050143174147137
   179132164146D73450
   000E38ABD316481FCF
   AF0D214ED50EF2FE0E
   F80EF6C42490870E4A
   8020161CF55D1418F8
   B050142164808CA267
   009F20"

To compile this you need an assembler:

  ASS [87E2]
  << -> lm
    << HEX "" 1 lm SIZE
       FOR i
         "#" lm i DUP2 1 + DUP SUB 3 ROLLD
         DUP SUB + + STR-> B->R CHR + 2
       STEP
       #3CEAA SYSEVAL
    >>
  >>

Make sure that the TACHK and the ASS program are typed in correctly
(use the original CHK program).
Put the string TACHK on stack level 1 and execute the ASS program.
After about 15 sec you get a combined object on level 1. Save it with the name
'ACHK'.
Now the ACHK is done and ASS and TACHK may be purged.
Normaly when calculate a checksum of a program the m-code ACHK program is
"only" 4 to 5 times faster because it take a fixed time to convert a program
into a string.

3) The following program takes a name or list of names as input and generates
an output-string of the name(s) with their checksums. A name of a directory may
be used.

  CHECK [ECC2]
  << { } + RCLF -> n f
    << "" 31 SF 1 n SIZE
      IF DUP
      THEN
        FOR i n i GET # 25AFCh SYSEVAL DUP
          IFERR RCL THEN
            DROP EVAL VARS CHECK UP
          ELSE
            ACHK ->STR 3 OVER SIZE 1 - SUB "["
            SWAP + "]" + 10 CHR + ROT ROT ->STR + SWAP
          END +
        NEXT
      ELSE DROP2 END
    >>
  >>

Regards,

Friedrich Schroeder

------------------------ END OF FRIEDRICH SCHROEDERS ARTICLE ----------------
