mixal-mode.el 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. ;;; mixal-mode.el --- Major mode for the mix asm language.
  2. ;; Copyright (C) 2003-2012 Free Software Foundation, Inc.
  3. ;; Author: Pieter E.J. Pareit <pieter.pareit@gmail.com>
  4. ;; Maintainer: Pieter E.J. Pareit <pieter.pareit@gmail.com>
  5. ;; Created: 09 Nov 2002
  6. ;; Version: 0.1
  7. ;; Keywords: languages, Knuth, mix, mixal, asm, mixvm, The Art Of Computer Programming
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; Major mode for the mix asm language.
  21. ;; The mix asm language is described in "The Art Of Computer Programming".
  22. ;;
  23. ;; For optimal use, also use GNU MDK. Compiling needs mixasm, running
  24. ;; and debugging needs mixvm and mixvm.el from GNU MDK. You can get
  25. ;; GNU MDK from `https://savannah.gnu.org/projects/mdk/' and
  26. ;; `ftp://ftp.gnu.org/pub/gnu/mdk'.
  27. ;;
  28. ;; To use this mode, place the following in your .emacs file:
  29. ;; `(load-file "/PATH-TO-FILE/mixal-mode.el")'.
  30. ;; When you load a file with the extension .mixal the mode will be started
  31. ;; automatic. If you want to start the mode manual, use `M-x mixal-mode'.
  32. ;; Font locking will work, the behavior of tabs is the same as Emacs's
  33. ;; default behavior. You can compile a source file with `C-c c' you can
  34. ;; run a compiled file with `C-c r' or run it in debug mode with `C-c d'.
  35. ;; You can get more information about a particular operation code by using
  36. ;; mixal-describe-operation-code or `C-h o'.
  37. ;;
  38. ;; Have fun.
  39. ;;; History:
  40. ;; Version 0.3:
  41. ;; 12/10/05: Stefan Monnier <monnier@iro.umontreal.ca>
  42. ;; Use font-lock-syntactic-keywords to detect/mark comments.
  43. ;; Use [^ \t\n]+ to match the operand part of a line.
  44. ;; Drop mixal-operation-codes.
  45. ;; Build the mixal-operation-codes-alist immediately.
  46. ;; Use `interactive' in mixal-describe-operation-code.
  47. ;; Remove useless ".*$" at the end of some regexps.
  48. ;; Fix the definition of comment-start-skip.
  49. ;; 08/10/05: sync mdk and emacs cvs
  50. ;; from emacs: compile-command and require-final-newline
  51. ;; from mdk: see version 0.2
  52. ;; correct my email address
  53. ;; Version 0.2:
  54. ;; 06/04/05: mixasm no longer needs -g option
  55. ;; fontlocking of comments works in all? cases now
  56. ;; added some more mixal-operation-codes
  57. ;; Version 0.1:
  58. ;; Version 0.1.1:
  59. ;; 22/11/02: bugfix in fontlocking, needed to add a '-' to the regex.
  60. ;; 19/11/02: completed implementing mixal-describe-operation-code.
  61. ;; 13/11/02: implemented compile, mixal-run and mixal-debug.
  62. ;; 10/11/02: implemented font-locking and syntax table.
  63. ;; 09/11/02: started mixal-mode.
  64. ;;; Code:
  65. (defvar compile-command)
  66. ;;; Key map
  67. (defvar mixal-mode-map
  68. (let ((map (make-sparse-keymap)))
  69. (define-key map "\C-c\C-c" 'compile)
  70. (define-key map "\C-c\C-r" 'mixal-run)
  71. (define-key map "\C-c\C-d" 'mixal-debug)
  72. (define-key map "\C-h\C-o" 'mixal-describe-operation-code)
  73. map)
  74. "Keymap for `mixal-mode'.")
  75. ;; (makunbound 'mixal-mode-map)
  76. ;;; Syntax table
  77. (defvar mixal-mode-syntax-table
  78. (let ((st (make-syntax-table)))
  79. ;; We need to do a bit more to make fontlocking for comments work.
  80. ;; See use of syntax-propertize-function.
  81. ;; (modify-syntax-entry ?* "<" st)
  82. (modify-syntax-entry ?\n ">" st)
  83. st)
  84. "Syntax table for `mixal-mode'.")
  85. (defvar mixal-font-lock-label-face 'font-lock-variable-name-face
  86. "Face name to use for label names.
  87. Default value is that of `font-lock-variable-name-face', but you can modify
  88. its value.")
  89. (defvar mixal-font-lock-operation-code-face 'font-lock-keyword-face
  90. "Face name to use for operation code names.
  91. Default value is that of `font-lock-keyword-face', but you can modify its
  92. value.")
  93. (defvar mixal-font-lock-assembly-pseudoinstruction-face 'font-lock-builtin-face
  94. "Face name to use for assembly pseudoinstruction names.
  95. Default value is that of `font-lock-builtin-face', but you can modify its
  96. value.")
  97. (defvar mixal-assembly-pseudoinstructions
  98. '("ORIG" "EQU" "CON" "ALF" "END")
  99. "List of possible assembly pseudoinstructions.")
  100. ;;;; Compilation
  101. ;; Output from mixasm is compatible with default behavior of emacs,
  102. ;; I just added a key (C-cc) and modified the make-command.
  103. ;;;; Indentation
  104. ;; Tabs works well by default.
  105. ;;;; Describe
  106. (defvar mixal-operation-codes-alist
  107. ;; FIXME: the codes FADD, FSUB, FMUL, FDIV, JRAD, and FCMP were in
  108. ;; mixal-operation-codes but not here. They should probably be added here.
  109. ;;
  110. ;; We used to define this with a backquote and subexps like ,(+ 8 3) for
  111. ;; better clarity, but the resulting code was too big and caused the
  112. ;; byte-compiler to eat up all the stack space. Even using
  113. ;; `eval-when-compile' didn't help because the byte-compiler insists on
  114. ;; compiling the code before evaluating it.
  115. '((LDA loading "load A" 8 field
  116. "Put in rA the contents of cell no. M.
  117. Uses a + when there is no sign in subfield. Subfield is left padded with
  118. zeros to make a word."
  119. 2)
  120. (LDX loading "load X" 15 field
  121. "Put in rX the contents of cell no. M.
  122. Uses a + when there is no sign in subfield. Subfield is left padded with
  123. zeros to make a word."
  124. 2)
  125. (LD1 loading "load I1" 9 field
  126. "Put in rI1 the contents of cell no. M.
  127. Uses a + when there is no sign in subfield. Subfield is left padded with
  128. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  129. to set anything more than that will result in undefined behavior."
  130. 2)
  131. (LD2 loading "load I2" 10 field
  132. "Put in rI2 the contents of cell no. M.
  133. Uses a + when there is no sign in subfield. Subfield is left padded with
  134. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  135. to set anything more than that will result in undefined behavior."
  136. 2)
  137. (LD3 loading "load I3" 11 field
  138. "Put in rI3 the contents of cell no. M.
  139. Uses a + when there is no sign in subfield. Subfield is left padded with
  140. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  141. to set anything more than that will result in undefined behavior."
  142. 2)
  143. (LD4 loading "load I4" 12 field
  144. "Put in rI4 the contents of cell no. M.
  145. Uses a + when there is no sign in subfield. Subfield is left padded with
  146. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  147. to set anything more than that will result in undefined behavior."
  148. 2)
  149. (LD5 loading "load I5" 13 field
  150. "Put in rI5 the contents of cell no. M.
  151. Uses a + when there is no sign in subfield. Subfield is left padded with
  152. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  153. to set anything more than that will result in undefined behavior."
  154. 2)
  155. (LD6 loading "load I6" 14 field
  156. "Put in rI6 the contents of cell no. M.
  157. Uses a + when there is no sign in subfield. Subfield is left padded with
  158. zeros to make a word. Index registers only have 2 bytes and a sign; trying
  159. to set anything more than that will result in undefined behavior."
  160. 2)
  161. (LDAN loading "load A negative" 16 field
  162. "Put in rA the contents of cell no. M, with opposite sign.
  163. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  164. Subfield is left padded with zeros to make a word."
  165. 2)
  166. (LDXN loading "load X negative" 23 field
  167. "Put in rX the contents of cell no. M, with opposite sign.
  168. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  169. Subfield is left padded with zeros to make a word."
  170. 2)
  171. (LD1N loading "load I1 negative" 17 field
  172. "Put in rI1 the contents of cell no. M, with opposite sign.
  173. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  174. Subfield is left padded with zeros to make a word. Index registers only
  175. have 2 bytes and a sign; trying to set anything more than that will result
  176. in undefined behavior."
  177. 2)
  178. (LD2N loading "load I2 negative" 18 field
  179. "Put in rI2 the contents of cell no. M, with opposite sign.
  180. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  181. Subfield is left padded with zeros to make a word. Index registers only
  182. have 2 bytes and a sign; trying to set anything more than that will result
  183. in undefined behavior."
  184. 2)
  185. (LD3N loading "load I3 negative" 19 field
  186. "Put in rI3 the contents of cell no. M, with opposite sign.
  187. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  188. Subfield is left padded with zeros to make a word. Index registers only
  189. have 2 bytes and a sign; trying to set anything more than that will result
  190. in undefined behavior."
  191. 2)
  192. (LD4N loading "load I4 negative" 20 field
  193. "Put in rI4 the contents of cell no. M, with opposite sign.
  194. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  195. Subfield is left padded with zeros to make a word. Index registers only
  196. have 2 bytes and a sign; trying to set anything more than that will result
  197. in undefined behavior."
  198. 2)
  199. (LD5N loading "load I5 negative" 21 field
  200. "Put in rI5 the contents of cell no. M, with opposite sign.
  201. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  202. Subfield is left padded with zeros to make a word. Index registers only
  203. have 2 bytes and a sign; trying to set anything more than that will result
  204. in undefined behavior."
  205. 2)
  206. (LD6N loading "load I6 negative" 22 field
  207. "Put in rI6 the contents of cell no. M, with opposite sign.
  208. Uses a + when there is no sign in subfield, otherwise use the opposite sign.
  209. Subfield is left padded with zeros to make a word. Index registers only
  210. have 2 bytes and a sign; trying to set anything more than that will result
  211. in undefined behavior."
  212. 2)
  213. (STA storing "store A" 24 field
  214. "Store in cell Nr. M the contents of rA.
  215. The modification of the operation code represents the subfield of the
  216. memory cell that is to be overwritten with bytes from a register. These
  217. bytes are taken beginning by the rightmost side of the register. The
  218. sign of the memory cell is not changed, unless it is part of the subfield."
  219. 2)
  220. (STX storing "store X" 31 field
  221. "Store in cell Nr. M the contents of rX.
  222. The modification of the operation code represents the subfield of the
  223. memory cell that is to be overwritten with bytes from a register. These
  224. bytes are taken beginning by the rightmost side of the register. The
  225. sign of the memory cell is not changed, unless it is part of the subfield."
  226. 2)
  227. (ST1 storing "store I1" 25 field
  228. "Store in cell Nr. M the contents of rI1.
  229. The modification of the operation code represents the subfield of the
  230. memory cell that is to be overwritten with bytes from a register. These
  231. bytes are taken beginning by the rightmost side of the register. The
  232. sign of the memory cell is not changed, unless it is part of the subfield.
  233. Because index registers only have 2 bytes and a sign, the rest of the bytes
  234. are assumed to be 0."
  235. 2)
  236. (ST2 storing "store I2" 26 field
  237. "Store in cell Nr. M the contents of rI2.
  238. The modification of the operation code represents the subfield of the
  239. memory cell that is to be overwritten with bytes from a register. These
  240. bytes are taken beginning by the rightmost side of the register. The
  241. sign of the memory cell is not changed, unless it is part of the subfield.
  242. Because index registers only have 2 bytes and a sign, the rest of the bytes
  243. are assumed to be 0."
  244. 2)
  245. (ST3 storing "store I3" 27 field
  246. "Store in cell Nr. M the contents of rI3.
  247. The modification of the operation code represents the subfield of the
  248. memory cell that is to be overwritten with bytes from a register. These
  249. bytes are taken beginning by the rightmost side of the register. The
  250. sign of the memory cell is not changed, unless it is part of the subfield.
  251. Because index registers only have 2 bytes and a sign, the rest of the bytes
  252. are assumed to be 0."
  253. 2)
  254. (ST4 storing "store I4" 28 field
  255. "Store in cell Nr. M the contents of rI4.
  256. The modification of the operation code represents the subfield of the
  257. memory cell that is to be overwritten with bytes from a register. These
  258. bytes are taken beginning by the rightmost side of the register. The
  259. sign of the memory cell is not changed, unless it is part of the subfield.
  260. Because index registers only have 2 bytes and a sign, the rest of the bytes
  261. are assumed to be 0."
  262. 2)
  263. (ST5 storing "store I5" 29 field
  264. "Store in cell Nr. M the contents of rI5.
  265. The modification of the operation code represents the subfield of the
  266. memory cell that is to be overwritten with bytes from a register. These
  267. bytes are taken beginning by the rightmost side of the register. The
  268. sign of the memory cell is not changed, unless it is part of the subfield.
  269. Because index registers only have 2 bytes and a sign, the rest of the bytes
  270. are assumed to be 0."
  271. 2)
  272. (ST6 storing "store I6" 30 field
  273. "Store in cell Nr. M the contents of rI6.
  274. The modification of the operation code represents the subfield of the
  275. memory cell that is to be overwritten with bytes from a register. These
  276. bytes are taken beginning by the rightmost side of the register. The
  277. sign of the memory cell is not changed, unless it is part of the subfield.
  278. Because index registers only have 2 bytes and a sign, the rest of the bytes
  279. are assumed to be 0."
  280. 2)
  281. (STJ storing "store J" 32 field
  282. "Store in cell Nr. M the contents of rJ.
  283. The modification of the operation code represents the subfield of the
  284. memory cell that is to be overwritten with bytes from a register. These
  285. bytes are taken beginning by the rightmost side of the register. The sign
  286. of rJ is always +, sign of the memory cell is not changed, unless it is
  287. part of the subfield. The default field for STJ is (0:2)."
  288. 2)
  289. (STZ storing "store zero" 33 field
  290. "Store in cell Nr. M '+ 0'.
  291. The modification of the operation code represents the subfield of the
  292. memory cell that is to be overwritten with zeros."
  293. 2)
  294. (ADD arithmetic "add" 1 field
  295. "Add to A the contents of cell Nr. M.
  296. Subfield is padded with zero to make a word.
  297. If the result is to large, the operation result modulo 1,073,741,823 (the
  298. maximum value storable in a MIX word) is stored in `rA', and the overflow
  299. toggle is set to TRUE."
  300. 2)
  301. (SUB arithmetic "subtract" 2 field
  302. "Subtract to A the contents of cell Nr. M.
  303. Subfield is padded with zero to make a word.
  304. If the result is to large, the operation result modulo 1,073,741,823 (the
  305. maximum value storable in a MIX word) is stored in `rA', and the overflow
  306. toggle is set to TRUE."
  307. 2)
  308. (MUL arithmetic "multiply" 3 field
  309. "Multiplies the contents of cell Nr. M with A, result is 10 bytes and stored in rA and rX.
  310. The sign is + if the sign of rA and cell M where the same, otherwise, it is -"
  311. 10)
  312. (DIV arithmetic "divide" 4 field
  313. "Both rA and rX are taken together and divided by cell Nr. M, quotient is placed in rA, remainder in rX.
  314. The sign is taken from rA, and after the divide the sign of rA is set to + when
  315. both the sign of rA and M where the same. Divide by zero and overflow of rA
  316. result in undefined behavior."
  317. 12)
  318. (ENTA address-transfer "enter A" 48
  319. "Literal value is stored in rA.
  320. Indexed, stores value of index in rA."
  321. 1)
  322. (ENTX address-transfer "enter X" 55
  323. "Literal value is stored in rX.
  324. Indexed, stores value of index in rX."
  325. 1)
  326. (ENT1 address-transfer "Enter rI1" 49
  327. "Literal value is stored in rI1.
  328. Indexed, stores value of index in rI1."
  329. 1)
  330. (ENT2 address-transfer "Enter rI2" 50
  331. "Literal value is stored in rI2.
  332. Indexed, stores value of index in rI2."
  333. 1)
  334. (ENT3 address-transfer "Enter rI3" 51
  335. "Literal value is stored in rI3.
  336. Indexed, stores value of index in rI3."
  337. 1)
  338. (ENT4 address-transfer "Enter rI4" 52
  339. "Literal value is stored in rI4.
  340. Indexed, stores value of index in rI4."
  341. 1)
  342. (ENT5 address-transfer "Enter rI5" 53
  343. "Literal value is stored in rI5.
  344. Indexed, stores value of index in rI5."
  345. 1)
  346. (ENT6 address-transfer "Enter rI6" 54
  347. "Literal value is stored in rI6.
  348. Indexed, stores value of index in rI6."
  349. 1)
  350. (ENNA address-transfer "enter negative A" 48
  351. "Literal value is stored in rA with opposite sign.
  352. Indexed, stores value of index in rA with opposite sign."
  353. 1)
  354. (ENNX address-transfer "enter negative X" 55
  355. "Literal value is stored in rX with opposite sign.
  356. Indexed, stores value of index in rX with opposite sign."
  357. 1)
  358. (ENN1 address-transfer "Enter negative rI1" 49
  359. "Literal value is stored in rI1 with opposite sign.
  360. Indexed, stores value of index in rI1 with opposite sign."
  361. 1)
  362. (ENN2 address-transfer "Enter negative rI2" 50
  363. "Literal value is stored in rI2 with opposite sign.
  364. Indexed, stores value of index in rI2 with opposite sign."
  365. 1)
  366. (ENN3 address-transfer "Enter negative rI3" 51
  367. "Literal value is stored in rI3 with opposite sign.
  368. Indexed, stores value of index in rI3 with opposite sign."
  369. 1)
  370. (ENN4 address-transfer "Enter negative rI4" 52
  371. "Literal value is stored in rI4 with opposite sign.
  372. Indexed, stores value of index in rI4 with opposite sign."
  373. 1)
  374. (ENN5 address-transfer "Enter negative rI5" 53
  375. "Literal value is stored in rI5 with opposite sign.
  376. Indexed, stores value of index in rI5 with opposite sign."
  377. 1)
  378. (ENN6 address-transfer "Enter negative rI6" 54
  379. "Literal value is stored in rI6 with opposite sign.
  380. Indexed, stores value of index in rI6 with opposite sign."
  381. 1)
  382. (INCA address-transfer "increase A" 48
  383. "Increase register A with the literal value of M.
  384. On overflow the overflow toggle is set."
  385. 1)
  386. (INCX address-transfer "increase X" 55
  387. "Increase register X with the literal value of M.
  388. On overflow the overflow toggle is set."
  389. 1)
  390. (INC1 address-transfer "increase I1" 49
  391. "Increase register I1 with the literal value of M.
  392. The result is undefined when the result does not fit in
  393. 2 bytes."
  394. 1)
  395. (INC2 address-transfer "increase I2" 50
  396. "Increase register I2 with the literal value of M.
  397. The result is undefined when the result does not fit in
  398. 2 bytes."
  399. 1)
  400. (INC3 address-transfer "increase I3" 51
  401. "Increase register I3 with the literal value of M.
  402. The result is undefined when the result does not fit in
  403. 2 bytes."
  404. 1)
  405. (INC4 address-transfer "increase I4" 52
  406. "Increase register I4 with the literal value of M.
  407. The result is undefined when the result does not fit in
  408. 2 bytes."
  409. 1)
  410. (INC5 address-transfer "increase I5" 53
  411. "Increase register I5 with the literal value of M.
  412. The result is undefined when the result does not fit in
  413. 2 bytes."
  414. 1)
  415. (INC6 address-transfer "increase I6" 54
  416. "Increase register I6 with the literal value of M.
  417. The result is undefined when the result does not fit in
  418. 2 bytes."
  419. 1)
  420. (DECA address-transfer "decrease A" 48
  421. "Decrease register A with the literal value of M.
  422. On overflow the overflow toggle is set."
  423. 1)
  424. (DECX address-transfer "decrease X" 55
  425. "Decrease register X with the literal value of M.
  426. On overflow the overflow toggle is set."
  427. 1)
  428. (DEC1 address-transfer "decrease I1" 49
  429. "Decrease register I1 with the literal value of M.
  430. The result is undefined when the result does not fit in
  431. 2 bytes."
  432. 1)
  433. (DEC2 address-transfer "decrease I2" 50
  434. "Decrease register I2 with the literal value of M.
  435. The result is undefined when the result does not fit in
  436. 2 bytes."
  437. 1)
  438. (DEC3 address-transfer "decrease I3" 51
  439. "Decrease register I3 with the literal value of M.
  440. The result is undefined when the result does not fit in
  441. 2 bytes."
  442. 1)
  443. (DEC4 address-transfer "decrease I4" 52
  444. "Decrease register I4 with the literal value of M.
  445. The result is undefined when the result does not fit in
  446. 2 bytes."
  447. 1)
  448. (DEC5 address-transfer "decrease I5" 53
  449. "Decrease register I5 with the literal value of M.
  450. The result is undefined when the result does not fit in
  451. 2 bytes."
  452. 1)
  453. (DEC6 address-transfer "decrease I6" 54
  454. "Decrease register I6 with the literal value of M.
  455. The result is undefined when the result does not fit in
  456. 2 bytes."
  457. 1)
  458. (CMPA comparison "compare A" 56 field
  459. "Compare contents of A with contents of M.
  460. The field specifier works on both fields. The comparison indicator
  461. is set to LESS, EQUAL or GREATER depending on the outcome."
  462. 2)
  463. (CMPX comparison "compare X" 63 field
  464. "Compare contents of rX with contents of M.
  465. The field specifier works on both fields. The comparison indicator
  466. is set to LESS, EQUAL or GREATER depending on the outcome."
  467. 2)
  468. (CMP1 comparison "compare I1" 57 field
  469. "Compare contents of rI1 with contents of M.
  470. The field specifier works on both fields. The comparison indicator
  471. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  472. have a value of 0."
  473. 2)
  474. (CMP2 comparison "compare I2" 58 field
  475. "Compare contents of rI2 with contents of M.
  476. The field specifier works on both fields. The comparison indicator
  477. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  478. have a value of 0."
  479. 2)
  480. (CMP3 comparison "compare I3" 59 field
  481. "Compare contents of rI3 with contents of M.
  482. The field specifier works on both fields. The comparison indicator
  483. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  484. have a value of 0."
  485. 2)
  486. (CMP4 comparison "compare I4" 60 field
  487. "Compare contents of rI4 with contents of M.
  488. The field specifier works on both fields. The comparison indicator
  489. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  490. have a value of 0."
  491. 2)
  492. (CMP5 comparison "compare I5" 61 field
  493. "Compare contents of rI5 with contents of M.
  494. The field specifier works on both fields. The comparison indicator
  495. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  496. have a value of 0."
  497. 2)
  498. (CMP6 comparison "compare I6" 62 field
  499. "Compare contents of rI6 with contents of M.
  500. The field specifier works on both fields. The comparison indicator
  501. is set to LESS, EQUAL or GREATER depending on the outcome. Bit 1,2 and 3
  502. have a value of 0."
  503. 2)
  504. (JMP jump "jump" 39
  505. "Unconditional jump.
  506. Register J is set to the value of the next instruction that would have
  507. been executed when there was no jump."
  508. 1)
  509. (JSJ jump "jump, save J" 39
  510. "Unconditional jump, but rJ is not modified."
  511. 1)
  512. (JOV jump "jump on overflow" 39
  513. "Jump if OV is set (and turn it off).
  514. Register J is set to the value of the next instruction that would have
  515. been executed when there was no jump."
  516. 1)
  517. (JNOV jump "Jump on no overflow" 39
  518. "Jump if OV is not set (and turn it off).
  519. Register J is set to the value of the next instruction that would have
  520. been executed when there was no jump."
  521. 1)
  522. (JL jump "Jump on less" 39
  523. "Jump if '[CM] = L'.
  524. Register J is set to the value of the next instruction that would have
  525. been executed when there was no jump."
  526. 1)
  527. (JE jump "Jump on equal" 39
  528. "Jump if '[CM] = E'.
  529. Register J is set to the value of the next instruction that would have
  530. been executed when there was no jump."
  531. 1)
  532. (JG jump "Jump on greater" 39
  533. "Jump if '[CM] = G'.
  534. Register J is set to the value of the next instruction that would have
  535. been executed when there was no jump."
  536. 1)
  537. (JGE jump "Jump on not less" 39
  538. "Jump if '[CM]' does not equal 'L'.
  539. Register J is set to the value of the next instruction that would have
  540. been executed when there was no jump."
  541. 1)
  542. (JNE jump "Jump on not equal" 39
  543. "Jump if '[CM]' does not equal 'E'.
  544. Register J is set to the value of the next instruction that would have
  545. been executed when there was no jump."
  546. 1)
  547. (JLE jump "Jump on not greater" 39
  548. "Jump if '[CM]' does not equal 'G'.
  549. Register J is set to the value of the next instruction that would have
  550. been executed when there was no jump."
  551. 1)
  552. (JAN jump "jump A negative" 40
  553. "Jump if the content of rA is negative.
  554. Register J is set to the value of the next instruction that would have
  555. been executed when there was no jump."
  556. 1)
  557. (JAZ jump "jump A zero" 40
  558. "Jump if the content of rA is zero.
  559. Register J is set to the value of the next instruction that would have
  560. been executed when there was no jump."
  561. 1)
  562. (JAP jump "jump A positive" 40
  563. "Jump if the content of rA is positive.
  564. Register J is set to the value of the next instruction that would have
  565. been executed when there was no jump."
  566. 1)
  567. (JANN jump "jump A non-negative" 40
  568. "Jump if the content of rA is non-negative.
  569. Register J is set to the value of the next instruction that would have
  570. been executed when there was no jump."
  571. 1)
  572. (JANZ jump "jump A non-zero" 40
  573. "Jump if the content of rA is non-zero.
  574. Register J is set to the value of the next instruction that would have
  575. been executed when there was no jump."
  576. 1)
  577. (JANP jump "jump A non-positive" 40
  578. "Jump if the content of rA is non-positive.
  579. Register J is set to the value of the next instruction that would have
  580. been executed when there was no jump."
  581. 1)
  582. (JXN jump "jump X negative" 47
  583. "Jump if the content of rX is negative.
  584. Register J is set to the value of the next instruction that would have
  585. been executed when there was no jump."
  586. 1)
  587. (JXZ jump "jump X zero" 47
  588. "Jump if the content of rX is zero.
  589. Register J is set to the value of the next instruction that would have
  590. been executed when there was no jump."
  591. 1)
  592. (JXP jump "jump X positive" 47
  593. "Jump if the content of rX is positive.
  594. Register J is set to the value of the next instruction that would have
  595. been executed when there was no jump."
  596. 1)
  597. (JXNN jump "jump X non-negative" 47
  598. "Jump if the content of rX is non-negative.
  599. Register J is set to the value of the next instruction that would have
  600. been executed when there was no jump."
  601. 1)
  602. (JXNZ jump "jump X non-zero" 47
  603. "Jump if the content of rX is non-zero.
  604. Register J is set to the value of the next instruction that would have
  605. been executed when there was no jump."
  606. 1)
  607. (JXNP jump "jump X non-positive" 47
  608. "Jump if the content of rX is non-positive.
  609. Register J is set to the value of the next instruction that would have
  610. been executed when there was no jump."
  611. 1)
  612. (J1N jump "jump I1 negative" 41
  613. "Jump if the content of rI1 is negative.
  614. Register J is set to the value of the next instruction that would have
  615. been executed when there was no jump."
  616. 1)
  617. (J1Z jump "jump I1 zero" 41
  618. "Jump if the content of rI1 is zero.
  619. Register J is set to the value of the next instruction that would have
  620. been executed when there was no jump."
  621. 1)
  622. (J1P jump "jump I1 positive" 41
  623. "Jump if the content of rI1 is positive.
  624. Register J is set to the value of the next instruction that would have
  625. been executed when there was no jump."
  626. 1)
  627. (J1NN jump "jump I1 non-negative" 41
  628. "Jump if the content of rI1 is non-negative.
  629. Register J is set to the value of the next instruction that would have
  630. been executed when there was no jump."
  631. 1)
  632. (J1NZ jump "jump I1 non-zero" 41
  633. "Jump if the content of rI1 is non-zero.
  634. Register J is set to the value of the next instruction that would have
  635. been executed when there was no jump."
  636. 1)
  637. (J1NP jump "jump I1 non-positive" 41
  638. "Jump if the content of rI1 is non-positive.
  639. Register J is set to the value of the next instruction that would have
  640. been executed when there was no jump."
  641. 1)
  642. (J2N jump "jump I2 negative" 41
  643. "Jump if the content of rI2 is negative.
  644. Register J is set to the value of the next instruction that would have
  645. been executed when there was no jump."
  646. 1)
  647. (J2Z jump "jump I2 zero" 41
  648. "Jump if the content of rI2 is zero.
  649. Register J is set to the value of the next instruction that would have
  650. been executed when there was no jump."
  651. 1)
  652. (J2P jump "jump I2 positive" 41
  653. "Jump if the content of rI2 is positive.
  654. Register J is set to the value of the next instruction that would have
  655. been executed when there was no jump."
  656. 1)
  657. (J2NN jump "jump I2 non-negative" 41
  658. "Jump if the content of rI2 is non-negative.
  659. Register J is set to the value of the next instruction that would have
  660. been executed when there was no jump."
  661. 1)
  662. (J2NZ jump "jump I2 non-zero" 41
  663. "Jump if the content of rI2 is non-zero.
  664. Register J is set to the value of the next instruction that would have
  665. been executed when there was no jump."
  666. 1)
  667. (J2NP jump "jump I2 non-positive" 41
  668. "Jump if the content of rI2 is non-positive.
  669. Register J is set to the value of the next instruction that would have
  670. been executed when there was no jump."
  671. 1)
  672. (J3N jump "jump I3 negative" 41
  673. "Jump if the content of rI3 is negative.
  674. Register J is set to the value of the next instruction that would have
  675. been executed when there was no jump."
  676. 1)
  677. (J3Z jump "jump I3 zero" 41
  678. "Jump if the content of rI3 is zero.
  679. Register J is set to the value of the next instruction that would have
  680. been executed when there was no jump."
  681. 1)
  682. (J3P jump "jump I3 positive" 41
  683. "Jump if the content of rI3 is positive.
  684. Register J is set to the value of the next instruction that would have
  685. been executed when there was no jump."
  686. 1)
  687. (J3NN jump "jump I3 non-negative" 41
  688. "Jump if the content of rI3 is non-negative.
  689. Register J is set to the value of the next instruction that would have
  690. been executed when there was no jump."
  691. 1)
  692. (J3NZ jump "jump I3 non-zero" 41
  693. "Jump if the content of rI3 is non-zero.
  694. Register J is set to the value of the next instruction that would have
  695. been executed when there was no jump."
  696. 1)
  697. (J3NP jump "jump I3 non-positive" 41
  698. "Jump if the content of rI3 is non-positive.
  699. Register J is set to the value of the next instruction that would have
  700. been executed when there was no jump."
  701. 1)
  702. (J4N jump "jump I4 negative" 41
  703. "Jump if the content of rI4 is negative.
  704. Register J is set to the value of the next instruction that would have
  705. been executed when there was no jump."
  706. 1)
  707. (J4Z jump "jump I4 zero" 41
  708. "Jump if the content of rI4 is zero.
  709. Register J is set to the value of the next instruction that would have
  710. been executed when there was no jump."
  711. 1)
  712. (J4P jump "jump I4 positive" 41
  713. "Jump if the content of rI4 is positive.
  714. Register J is set to the value of the next instruction that would have
  715. been executed when there was no jump."
  716. 1)
  717. (J4NN jump "jump I4 non-negative" 41
  718. "Jump if the content of rI4 is non-negative.
  719. Register J is set to the value of the next instruction that would have
  720. been executed when there was no jump."
  721. 1)
  722. (J4NZ jump "jump I4 non-zero" 41
  723. "Jump if the content of rI4 is non-zero.
  724. Register J is set to the value of the next instruction that would have
  725. been executed when there was no jump."
  726. 1)
  727. (J4NP jump "jump I4 non-positive" 41
  728. "Jump if the content of rI4 is non-positive.
  729. Register J is set to the value of the next instruction that would have
  730. been executed when there was no jump."
  731. 1)
  732. (J5N jump "jump I5 negative" 41
  733. "Jump if the content of rI5 is negative.
  734. Register J is set to the value of the next instruction that would have
  735. been executed when there was no jump."
  736. 1)
  737. (J5Z jump "jump I5 zero" 41
  738. "Jump if the content of rI5 is zero.
  739. Register J is set to the value of the next instruction that would have
  740. been executed when there was no jump."
  741. 1)
  742. (J5P jump "jump I5 positive" 41
  743. "Jump if the content of rI5 is positive.
  744. Register J is set to the value of the next instruction that would have
  745. been executed when there was no jump."
  746. 1)
  747. (J5NN jump "jump I5 non-negative" 41
  748. "Jump if the content of rI5 is non-negative.
  749. Register J is set to the value of the next instruction that would have
  750. been executed when there was no jump."
  751. 1)
  752. (J5NZ jump "jump I5 non-zero" 41
  753. "Jump if the content of rI5 is non-zero.
  754. Register J is set to the value of the next instruction that would have
  755. been executed when there was no jump."
  756. 1)
  757. (J5NP jump "jump I5 non-positive" 41
  758. "Jump if the content of rI5 is non-positive.
  759. Register J is set to the value of the next instruction that would have
  760. been executed when there was no jump."
  761. 1)
  762. (J6N jump "jump I6 negative" 41
  763. "Jump if the content of rI6 is negative.
  764. Register J is set to the value of the next instruction that would have
  765. been executed when there was no jump."
  766. 1)
  767. (J6Z jump "jump I6 zero" 41
  768. "Jump if the content of rI6 is zero.
  769. Register J is set to the value of the next instruction that would have
  770. been executed when there was no jump."
  771. 1)
  772. (J6P jump "jump I6 positive" 41
  773. "Jump if the content of rI6 is positive.
  774. Register J is set to the value of the next instruction that would have
  775. been executed when there was no jump."
  776. 1)
  777. (J6NN jump "jump I6 non-negative" 41
  778. "Jump if the content of rI6 is non-negative.
  779. Register J is set to the value of the next instruction that would have
  780. been executed when there was no jump."
  781. 1)
  782. (J6NZ jump "jump I6 non-zero" 41
  783. "Jump if the content of rI6 is non-zero.
  784. Register J is set to the value of the next instruction that would have
  785. been executed when there was no jump."
  786. 1)
  787. (J6NP jump "jump I6 non-positive" 41
  788. "Jump if the content of rI6 is non-positive.
  789. Register J is set to the value of the next instruction that would have
  790. been executed when there was no jump."
  791. 1)
  792. (SLA miscellaneous "shift left A" 6
  793. "Shift to A, M bytes left.
  794. Hero's will be added to the right."
  795. 2)
  796. (SRA miscellaneous "shift right A" 6
  797. "Shift to A, M bytes right.
  798. Zeros will be added to the left."
  799. 2)
  800. (SLAX miscellaneous "shift left AX" 6
  801. "Shift AX, M bytes left.
  802. Zeros will be added to the right."
  803. 2)
  804. (SRAX miscellaneous "shift right AX" 6
  805. "Shift AX, M bytes right.
  806. Zeros will be added to the left."
  807. 2)
  808. (SLC miscellaneous "shift left AX circularly" 6
  809. "Shift AX, M bytes left circularly.
  810. The bytes that fall off to the left will be added to the right."
  811. 2)
  812. (SRC miscellaneous "shift right AX circularly" 6
  813. "Shift AX, M bytes right circularly.
  814. The bytes that fall off to the right will be added to the left."
  815. 2)
  816. (MOVE miscellaneous "move" 7 number
  817. "Move MOD words from M to the location stored in rI1."
  818. (+ 1 (* 2 number)))
  819. (NOP miscellaneous "no operation" 0 ignored
  820. "No operation, M and F are not used by the machine."
  821. 1)
  822. (HLT miscellaneous "halt" 5
  823. "Halt.
  824. Stop instruction fetching."
  825. 1)
  826. (IN input-output "input" 36 unit
  827. "Transfer a block of words from the specified unit to memory.
  828. The transfer starts at address M."
  829. 1)
  830. (OUT input-output "output" 37 unit
  831. "Transfer a block of words from memory.
  832. The transfer starts at address M to the specified unit."
  833. 1)
  834. (IOC input-output "input-output control" 35 unit
  835. "Perform a control operation.
  836. The control operation is given by M on the specified unit."
  837. 1)
  838. (JRED input-output "jump ready" 38 unit
  839. "Jump to M if the specified unit is ready."
  840. 1)
  841. (JBUS input-output "jump busy" 34 unit
  842. "Jump to M if the specified unit is busy."
  843. 1)
  844. (NUM conversion "convert to numeric" 5
  845. "Convert rAX to its numerical value and store it in rA.
  846. the register rAX is assumed to contain a character representation of
  847. a number."
  848. 10)
  849. (CHAR conversion "convert to characters" 5
  850. "Convert the number stored in rA to a character representation.
  851. The converted character representation is stored in rAX."
  852. 10))
  853. "Alist that contains all the possible operation codes for mix.
  854. Each elt has the form
  855. (OP-CODE GROUP FULL-NAME C-BYTE F-BYTE DESCRIPTION EXECUTION-TIME)
  856. Where OP-CODE is the text of the opcode as a symbol,
  857. FULL-NAME is the human readable name as a string,
  858. C-BYTE is the operation code telling what operation is to be performed,
  859. F-BYTE holds a modification of the operation code which can be a symbol
  860. or a number,
  861. DESCRIPTION contains an string with a description about the operation code and
  862. EXECUTION-TIME holds info about the time it takes, number or string.")
  863. ;; (makunbound 'mixal-operation-codes-alist)
  864. ;;; Font-locking:
  865. (defconst mixal-syntax-propertize-function
  866. (syntax-propertize-rules
  867. ;; Normal comments start with a * in column 0 and end at end of line.
  868. ("^\\*" (0 "<"))
  869. ;; Every line can end with a comment which is placed after the operand.
  870. ;; I assume here that mnemonics without operands can not have a comment.
  871. ("^[[:alnum:]]*[ \t]+[[:alnum:]]+[ \t]+[^ \n\t]+[ \t]*\\([ \t]\\)[^\n \t]"
  872. (1 "<"))))
  873. (defvar mixal-font-lock-keywords
  874. `(("^\\([A-Z0-9a-z]+\\)"
  875. (1 mixal-font-lock-label-face))
  876. (,(regexp-opt (mapcar (lambda (x) (symbol-name (car x)))
  877. mixal-operation-codes-alist) 'words)
  878. . mixal-font-lock-operation-code-face)
  879. (,(regexp-opt mixal-assembly-pseudoinstructions 'words)
  880. . mixal-font-lock-assembly-pseudoinstruction-face)
  881. ("^[A-Z0-9a-z]*[ \t]+[A-ZO-9a-z]+[ \t]+\\(=.*=\\)"
  882. (1 font-lock-constant-face)))
  883. "Keyword highlighting specification for `mixal-mode'.")
  884. ;; (makunbound 'mixal-font-lock-keywords)
  885. (defvar mixal-describe-operation-code-history nil
  886. "History list for describe operation code.")
  887. (defun mixal-describe-operation-code (op-code)
  888. "Display the full documentation of OP-CODE."
  889. (interactive
  890. (list
  891. (let* ((completion-ignore-case t)
  892. ;; we already have a list, but it is not in the right format
  893. ;; transform it to a valid table so completion can use it
  894. (table (mapcar (lambda (elm) (cons (symbol-name (car elm)) nil))
  895. mixal-operation-codes-alist))
  896. ;; prompt is different depending on we are close to a valid op-code
  897. (have-default (assq (intern-soft (current-word))
  898. mixal-operation-codes-alist))
  899. (prompt (concat "Describe operation code "
  900. (if have-default
  901. (concat "(default " (current-word) "): ")
  902. ": "))))
  903. ;; As the operation code to the user.
  904. (completing-read prompt table nil t nil
  905. 'mixal-describe-operation-code-history
  906. (current-word)))))
  907. ;; get the info on the op-code and output it to the help buffer
  908. (let ((op-code-help (assq (intern-soft op-code) mixal-operation-codes-alist)))
  909. (when op-code-help
  910. (with-output-to-temp-buffer (buffer-name (get-buffer-create "*Help*"))
  911. (princ op-code) (princ " is an mix operation code\n\n")
  912. (princ (nth 5 op-code-help)) (terpri) (terpri)
  913. (princ " group: ") (princ (nth 1 op-code-help)) (terpri)
  914. (princ " nice name: ") (princ (nth 2 op-code-help)) (terpri)
  915. (princ " OPCODE / C: ") (princ (nth 3 op-code-help)) (terpri)
  916. (princ " MOD / F: ") (princ (nth 4 op-code-help)) (terpri)
  917. (princ " time: ") (princ (nth 6 op-code-help)) (terpri)))))
  918. ;;;; Running
  919. (defun mixal-run ()
  920. "Run mixal file in current buffer, assumes that file has been compiled."
  921. (interactive)
  922. (if (fboundp 'mixvm)
  923. (mixvm (concat "mixvm -r -t -d "
  924. (file-name-sans-extension (buffer-file-name))))
  925. (error "mixvm.el needs to be loaded to run `mixvm'")))
  926. (defun mixal-debug ()
  927. "Start mixvm for debugging.
  928. Assumes that file has been compiled with debugging support."
  929. (interactive)
  930. (if (fboundp 'mixvm)
  931. (mixvm (concat "mixvm "
  932. (file-name-sans-extension (buffer-file-name))))
  933. (error "mixvm.el needs to be loaded to run `mixvm'")))
  934. ;;;###autoload
  935. (define-derived-mode mixal-mode prog-mode "mixal"
  936. "Major mode for the mixal asm language."
  937. (set (make-local-variable 'comment-start) "*")
  938. (set (make-local-variable 'comment-start-skip) "^\\*[ \t]*")
  939. (set (make-local-variable 'font-lock-defaults)
  940. `(mixal-font-lock-keywords))
  941. (set (make-local-variable 'syntax-propertize-function)
  942. mixal-syntax-propertize-function)
  943. ;; might add an indent function in the future
  944. ;; (set (make-local-variable 'indent-line-function) 'mixal-indent-line)
  945. (set (make-local-variable 'compile-command) (concat "mixasm "
  946. buffer-file-name)))
  947. (provide 'mixal-mode)
  948. ;;; mixal-mode.el ends here