home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / aaa / aux / defs < prev    next >
Encoding:
Text File  |  1986-11-30  |  1.1 KB  |  43 lines

  1. # The heart of the assembler, interpreting definitions, keeping location
  2. # counters, and assigning addresses to code.
  3. BEGIN { locs["d"] = 0 ; locs["b"] = 0; locs["t"] = 0; which = "d" }
  4. /^[^.].*=.+$/ {            # Symbol definition.
  5.     n = split($0, bits, "=")
  6.     it = bits[2]
  7.     while (it < 0)
  8.         it += 65536
  9.     print bits[1] "=" it
  10.     print "/" bits[1] "=" int(it%256 + 0.001)
  11.     print "\\" bits[1] "=" int(it/256 + 0.001)
  12.     print "%" bits[1] "=" "/" bits[2] "%"
  13.     print "%%" bits[1] "=" "\\" bits[2] "%"
  14. }
  15. /^\.=[0-9]+$/ {            # Set location counter.
  16.     locs[which] = substr($0, 3)
  17. }
  18. /^\.=\.\+[0-9]+$/ {        # Bump location counter, allocating space.
  19.     locs[which] += substr($0, 5)
  20. }
  21. /:/ {                # Label.
  22.     n = split($0, bits, ":")
  23.     print bits[1] "=" locs[which]
  24.     print "/" bits[1] "=" int(locs[which]%256 + 0.001)
  25.     print "\\" bits[1] "=" int(locs[which]/256 + 0.001)
  26.     print "%" bits[1] "=" "/" locs[which] "%"
  27.     print "%%" bits[1] "=" "\\" locs[which] "%"
  28. }
  29. /^\.text$/ {
  30.     which = "t"
  31. }
  32. /^\.data$/ {
  33.     which = "d"
  34. }
  35. /^\.bss$/ {
  36.     which = "b"
  37. }
  38. /^$/    { next }
  39. $0 !~ /[=:]/ && $0 !~ /^\./ {    # Code.
  40.     print locs[which] which "\t" $0
  41.     locs[which]++
  42. }
  43.