home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / aaa / 6801 / final < prev    next >
Text File  |  1986-11-30  |  1KB  |  46 lines

  1. # Final postprocessing, to handle high/low byte-extraction operators,
  2. # and compute PC-relative offsets.  The only thing that is really
  3. # machine-dependent here is the pcbias's, which reflect the difference
  4. # between the location of an offset byte and the PC which should be
  5. # used in computing it (i.e., how far ahead the PC is by the time the
  6. # byte is used to alter the PC).
  7. BEGIN {
  8.     FS = "\t"
  9.     OFS = "\t"
  10.     pcbiaslo = 1
  11.     pcbiashi = 2
  12.     if (pcbiaslo > pcbiashi)
  13.         pcbiasmax = pcbiaslo
  14.     else
  15.         pcbiasmax = pcbiashi
  16. }
  17. {
  18.     if ($2 == "") {            # Number or something, not symbol.
  19.         if ($3 ~ /^\/[0-9]/) {
  20.             it = substr($3, 2);
  21.             while (it < 0)
  22.                 it += 65536
  23.             print $1, int(it%256 + 0.001), "# " $3
  24.         } else if ($3 ~ /^\\[0-9]/) {
  25.             it = substr($3, 2);
  26.             while (it < 0)
  27.                 it += 65536
  28.             print $1, int(it/256 + 0.001), "# " $3
  29.         } else
  30.             print $1, $3
  31.     } else if ($2 ~ /^[0-9]+$/)    # Symbol, ordinary value.
  32.         print $1, $2, "# " $3
  33.     else if ($2 ~ /%$/) {        # Symbol, PC-relative value.
  34.         base = substr($1, 1, length($1)-1)
  35.         it = substr($2, 2, length($2)-2)
  36.         p = it - base
  37.         while (p < pcbiasmax)
  38.             p += 65536
  39.         if ($2 ~ /^\//)
  40.             print $1, int((p - pcbiaslo)%256 + 0.001), "# " $3
  41.         else
  42.             print $1, int((p - pcbiashi)/256 + 0.001), "# " $3
  43.     } else                # Something else.
  44.         print $1, $2, "# " $3
  45. }
  46.