home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 113_01 / a15tbl2.asm < prev    next >
Assembly Source File  |  1985-03-10  |  6KB  |  280 lines

  1.     TITLE    'Machine Language Functions for 1805A Cross-Assembler V 1.2'
  2.     PAGE    60
  3. ;
  4. ;    1805A Cross-Assembler Version 1.2
  5. ;
  6. ;    Copyright (c) 1980, 82, 83, 85 William C. Colley, III.
  7. ;
  8. ;    July 1982 -- Adapted from my 1802 cross-assembler.  WCC3.
  9. ;
  10. ;    Vers 1.0 -- March 1983 -- Added 1805A opcodes to the 1805 set.  WCC3.
  11. ;
  12. ;    Vers 1.1 -- March 1983 -- Added CPU pseudo-op to combine 1802 and 1805A
  13. ;            cross-assemblers into a single program.  WCC3.
  14. ;
  15. ;    Vers 1.2 -- June 1985 -- Fixed IF block nesting mechanism bug and bug
  16. ;            in 1805A SCAL opcode.  WCC3.
  17. ;
  18. ; File:    A15TBL2.ASM
  19. ;
  20. ; Machine Language Functions -- Module #2 of 2.
  21. ;
  22.     MACLIB    CMAC
  23. ;
  24. ; Here I build the directory to the functions in this CRL file:
  25. ;
  26.     DIRECT
  27.     DEFINE    GETATTR        ;First entry.
  28.     DEFINE    GETOPR        ;Second entry.
  29.     DEFINE    NUMOPRS        ;Third entry.
  30.     ENDDIR
  31. ;
  32. ; Arguments are passed via offsets from the stack pointer.
  33. ; They are defined as follows:
  34. ;
  35. ARG0    EQU    2        ;First argument.
  36. ARG1    EQU    4        ;Second argument.
  37. ARG2    EQU    6        ;Third argument.
  38. ARG3    EQU    8        ;Fourth argument.
  39. ;
  40.     PAGE
  41. ;
  42. ; This function removes the parity bit from its argument and looks it up in
  43. ; a table.  The table classifies the character into one of the following bins
  44. ; returning the appropriate code.
  45. ;
  46. ALPHA    EQU    0    ;Alphabetic.
  47. NUMERC    EQU    1    ;Numeric (0-9).
  48. ENDLIN    EQU    2    ;End of line markers (CR ;).
  49. COMMA    EQU    3    ;Field separators (,).
  50. OPERAT    EQU    4    ;Operators (* + / - > < = ( )).
  51. QUOTE    EQU    5    ;String delimiters (' ").
  52. BLANK    EQU    7    ;White space character (SPC TAB).
  53. TRASH    EQU    8    ;Other control characters.
  54. ;
  55. ; The function is called as follows:
  56. ;
  57. ;    getattr(byte);
  58. ;
  59. ;    byte    Character value to be looked up.
  60. ;
  61. BYTE    EQU    ARG0
  62. ;
  63.     PRELUDE    GETATTR
  64. ;
  65.     LXI    H, BYTE        ;Get byte to look up.
  66.     DAD    SP
  67.     MOV    A,M
  68.     ANI    7FH        ;Strip parity bit.
  69. ;
  70.     RELOC    <LXI H,>,ATTTBL    ;Index into table.
  71.     ADD    L
  72.     MOV    L,A
  73.     MVI    A, 0
  74.     ADC    H
  75.     MOV    H,A
  76. ;
  77.     MOV    L,M        ;Return result.
  78.     MVI    H, 0
  79.     RET
  80. ;
  81. ; Attribute table itself:
  82. ;
  83. ;    First a fill macro to shorten the source code:
  84. ;
  85. BLOCK    MACRO    VALU,SIZE
  86.     REPT    SIZE
  87.     DB    VALU
  88.     ENDM
  89.     ENDM
  90. ;
  91. ATTTBL:    BLOCK    TRASH,9        ; ^@ thru ^H
  92.     DB    BLANK        ; TAB
  93.     DB    ENDLIN        ; LF
  94.     DB    TRASH        ; ^K
  95.     DB    TRASH        ; FF
  96.     DB    TRASH        ; CR
  97.     BLOCK    TRASH,18    ; All other control characters
  98.     DB    BLANK        ; SPC
  99.     DB    ALPHA        ; Exclamation point.
  100.     DB    QUOTE        ; "
  101.     DB    ALPHA        ; #
  102.     DB    ALPHA        ; $
  103.     DB    ALPHA        ; %
  104.     DB    ALPHA        ; &
  105.     DB    QUOTE        ; '
  106.     DB    OPERAT        ; (
  107.     DB    OPERAT        ; )
  108.     DB    OPERAT        ; *
  109.     DB    OPERAT        ; +
  110.     DB    COMMA        ; ,
  111.     DB    OPERAT        ; -
  112.     DB    ALPHA        ; .
  113.     DB    OPERAT        ; /
  114.     BLOCK    NUMERC,10    ; 0 thru 9
  115.     DB    ALPHA        ; :
  116.     DB    ENDLIN        ; ;
  117.     DB    OPERAT        ; <
  118.     DB    OPERAT        ; =
  119.     DB    OPERAT        ; >
  120.     DB    ALPHA        ; ?
  121.     DB    ALPHA        ; @
  122.     BLOCK    ALPHA,26    ; A thru Z
  123.     DB    ALPHA        ; [
  124.     DB    ALPHA        ; \
  125.     DB    ALPHA        ; ]
  126.     DB    ALPHA        ; ^
  127.     DB    ALPHA        ; _
  128.     DB    ALPHA        ; `
  129.     BLOCK    ALPHA,26    ; small A thru small Z
  130.     DB    ALPHA        ; {
  131.     DB    ALPHA        ; |
  132.     DB    ALPHA        ; }
  133.     DB    ALPHA        ; ~
  134.     DB    TRASH        ; RUB
  135. ;
  136.     POSTLUDE GETATTR
  137. ;
  138.     PAGE
  139. ;
  140. ; This function gets operator number num from the operator table.  The function
  141. ; returns 0 if the operator was not found, 1 if it was.
  142. ;
  143. ; Function is called as follows:
  144. ;
  145. ;    getopr(num,opratr,bs,token);
  146. ;
  147. ;    num    Character containing the number of the desired entry.
  148. ;            0 represents the first entry in the table.  The
  149. ;            table is in alphabetical order for the benefit
  150. ;            of the binary searching routine (written in C).
  151. ;    opratr    Pointer to a 5-character array which will receive the
  152. ;            operator's name (null terminated).
  153. ;    bs    A dud argument to maintain compatibility with getopc.
  154. ;    token    A pointer to a character that will receive the operator's
  155. ;            token byte.
  156. ;
  157. NUM    EQU    ARG0
  158. OPRATR    EQU    ARG1
  159. BS    EQU    ARG2
  160. TOKEN    EQU    ARG3
  161. ;
  162.     PRELUDE    GETOPR
  163. ;
  164.     LXI    H, NUM        ;Get entry number.
  165.     DAD    SP
  166.     MOV    A,M
  167.     CPI    OPRTLL        ;Entry in table?
  168.     LXI    H, 0        ;If not, return 0.
  169.     RNC
  170. ;
  171.     MOV    L,A        ;Find entry by computing
  172.     ADD    A        ;(5 * num) + table base.
  173.     ADD    A
  174.     ADD    L
  175.     MOV    L,A
  176.     RELOC    <LXI D,>,OPRTBL
  177.     DAD    D
  178.     MOV    E,L
  179.     MOV    D,H
  180. ;
  181.     LXI    H, OPRATR    ;Find operator return area.
  182.     DAD    SP
  183.     MOV    A,M
  184.     INX    H
  185.     MOV    H,M
  186.     MOV    L,A
  187. ;
  188.     PUSH    B        ;Move operator name to return area.
  189.     MVI    C, 4
  190. MOVOPR:    LDAX    D
  191.     INX    D
  192.     MOV    M,A
  193.     INX    H
  194.     DCR    C
  195.     RELOC    JNZ,MOVOPR
  196.     POP    B
  197. ;
  198.     MVI    M, 0        ;Terminate operator name.
  199. ;
  200.     LXI    H, TOKEN    ;Find token return area.
  201.     DAD    SP
  202.     MOV    A,M
  203.     INX    H
  204.     MOV    H,M
  205.     MOV    L,A
  206. ;
  207.     LDAX    D        ;Move token to return area.
  208.     MOV    M,A
  209. ;
  210.     LXI    H, 1        ;Return 1 for successful get.
  211.     RET
  212. ;
  213. ; The operator table itself:
  214. ;
  215. ;    The operator tokens are as follows:
  216. ;
  217. GETKN    EQU    1
  218. NETKN    EQU    2
  219. LETKN    EQU    3
  220. ANDTKN    EQU    4
  221. ORTKN    EQU    5
  222. XORTKN    EQU    6
  223. NOTTKN    EQU    7
  224. MODTKN    EQU    8
  225. SHLTKN    EQU    9
  226. SHRTKN    EQU    10
  227. HITKN    EQU    11
  228. LOWTKN    EQU    12
  229. GTTKN    EQU    '>'
  230. EQTKN    EQU    '='
  231. LTTKN    EQU    '<'
  232. ;
  233. OPRTBL:    DB    'AND', 0,    ANDTKN
  234.     DB    'EQ', 0, 0,    EQTKN
  235.     DB    'GE', 0, 0,    GETKN
  236.     DB    'GT', 0, 0,    GTTKN
  237.     DB    'HIGH',        HITKN
  238.     DB    'LE', 0, 0,    LETKN
  239.     DB    'LOW', 0,    LOWTKN
  240.     DB    'LT', 0, 0,    LTTKN
  241.     DB    'MOD', 0,    MODTKN
  242.     DB    'NE', 0, 0,    NETKN
  243.     DB    'NOT', 0,    NOTTKN
  244.     DB    'OR', 0, 0,    ORTKN
  245.     DB    'SHL', 0,    SHLTKN
  246.     DB    'SHR', 0,    SHRTKN
  247.     DB    'XOR', 0,    XORTKN
  248. ;
  249. OPRTLL    EQU    ($-OPRTBL)/5    ;Calculate length of table.
  250. ;
  251.     POSTLUDE GETOPR
  252. ;
  253.     PAGE
  254. ;
  255. ; This function returns the number of operators in the operator table
  256. ; for the benefit of the binary searching routine (written in C).
  257. ;
  258. ; This function is called as follows:
  259. ;
  260. ;    numoprs();
  261. ;
  262.     PRELUDE    NUMOPRS
  263. ;
  264.     LXI    H, OPRTLL    ;Return number of opcodes.
  265.     RET
  266. ;
  267.     POSTLUDE NUMOPRS
  268. ;
  269. ; End of package:
  270. ;
  271.     END
  272. itself:
  273. ;
  274. ;    The operator tokens are as follows:
  275. ;
  276. GETKN    EQU    1
  277. NETKN    EQU    2
  278. LETKN    EQU    3
  279. ANDTKN    EQU    4
  280. ORT