1 ; xstormy16 CPU core description. -*- Scheme -*-
2 ; Copyright 2011 Free Software Foundation, Inc.
4 ; Contributed by Red Hat Inc;
6 ; This file is part of the GNU Binutils.
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation; either version 3 of the License, or
11 ; (at your option) any later version.
13 ; This program 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.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 (define-rtl-version 0 8)
25 (include "simplify.inc")
29 (comment "Xstormy16 architecture")
37 (comment "Xstormy16 instruction set")
38 (default-insn-word-bitsize 32)
39 (default-insn-bitsize 32)
40 ; FIXME base-insn-bitsize should be 16 too, but at present CGEN has
41 ; no support for instruction sets with opcode bits past
42 ; base-insn-bitsize, so we must set it to at least 20.
43 (base-insn-bitsize 32)
48 (comment "Xstormy16 CPU core")
51 (insn-chunk-bitsize 16)
57 (comment "Xstormy16 CPU core")
64 (comment "Xstormy16 CPU core")
65 (unit u-exec "Execution Unit" ()
70 ; IDOC attribute for instruction documentation.
76 (comment "insn kind for documentation")
83 (PRIV - () "Priviledged")
84 (MISC - () "Miscellaneous")
92 (comment "program counter")
95 (set (newval) (c-call "h_pc_set_handler" newval))
101 (values (r0 0) (r1 1) (r2 2) (r3 3)
102 (r4 4) (r5 5) (r6 6) (r7 7)
103 (r8 8) (r9 9) (r10 10) (r11 11)
104 (r12 12) (r13 13) (r14 14) (r15 15)
110 (values (r8 0) (r9 1) (r10 2) (r11 3)
111 (r12 4) (r13 5) (r14 6) (r15 7)
116 (comment "registers")
117 (type register WI (16))
118 (indices extern-keyword gr-names)
119 (get (index) (and #xFFFF (raw-reg h-gr index)))
120 (set (index newval) (c-call "h_gr_set_handler" index newval))
125 (comment "Rb registers")
127 (type register SI(8))
128 (indices extern-keyword gr-Rb-names)
129 (get (index) (reg h-gr (add index 8)))
130 (set (index newval) (set (reg h-gr (add index 8)) newval))
135 (comment "Rbj registers")
137 (type register SI(2))
138 (indices extern-keyword gr-Rb-names)
139 (get (index) (reg h-gr (add index 8)))
140 (set (index newval) (set (reg h-gr (add index 8)) newval))
145 (comment "Register number field of the PSW")
148 (get () (and #xF (srl psw 12)))
149 (set (newval) (set psw (or (and psw #xFFF)
150 (sll HI newval 12)))))
152 (define-pmacro (define-psw-field fnam hnam index)
157 (get () (and 1 (srl psw index)))
158 (set (newval) (set psw (or (and psw (inv (sll HI 1 index)))
159 (sll HI newval index)))))
160 ;(dnop fnam "" (SEM-ONLY) hnam f-nil)
162 (define-psw-field psw-z8 h-z8 0)
163 (dnop psw-z8 "" (SEM-ONLY) h-z8 f-nil)
164 (define-psw-field psw-z16 h-z16 1)
165 (dnop psw-z16 "" (SEM-ONLY) h-z16 f-nil)
166 (define-psw-field psw-cy h-cy 2)
167 (dnop psw-cy "" (SEM-ONLY) h-cy f-nil)
168 (define-psw-field psw-hc h-hc 3)
169 (dnop psw-hc "" (SEM-ONLY) h-hc f-nil)
170 (define-psw-field psw-ov h-ov 4)
171 (dnop psw-ov "" (SEM-ONLY) h-ov f-nil)
172 (define-psw-field psw-pt h-pt 5)
173 (dnop psw-pt "" (SEM-ONLY) h-pt f-nil)
174 (define-psw-field psw-s h-s 6)
175 (dnop psw-s "" (SEM-ONLY) h-s f-nil)
179 (comment "Condition of a branch instruction")
180 (type immediate (UINT 4))
182 (("ge" 0) ("nc" 1) ("lt" 2) ("c" 3)
183 ("gt" 4) ("hi" 5) ("le" 6) ("ls" 7)
184 ("pl" 8) ("nv" 9) ("mi" 10) ("v" 11)
185 ("nz.b" 12) ("nz" 13) ("z.b" 14) ("z" 15)))
190 (comment "Data size")
191 (type immediate (UINT 1))
192 (values keyword "" ((".b" 0) (".w" 1) ("" 1)))
196 ; Instruction fields, and the corresponding operands.
199 (dnf f-Rd "general register destination" () 12 4)
200 (dnop Rd "general register destination" () h-gr f-Rd)
202 (dnf f-Rdm "general register destination" () 13 3)
203 (dnop Rdm "general register destination" () h-gr f-Rdm)
205 (dnf f-Rm "general register for memory" () 4 3)
206 (dnop Rm "general register for memory" () h-gr f-Rm)
208 (dnf f-Rs "general register source" () 8 4)
209 (dnop Rs "general register source" () h-gr f-Rs)
211 (dnf f-Rb "base register" () 17 3)
212 (dnop Rb "base register" () h-Rb f-Rb)
214 (dnf f-Rbj "base register for jump" () 11 1)
215 (dnop Rbj "base register for jump" () h-Rbj f-Rbj)
217 ; Main opcodes in 4 bit chunks
219 (dnf f-op1 "opcode" () 0 4)
220 (define-normal-insn-enum insn-op1 "insn op enums" () OP1_ f-op1
221 ( "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ))
223 (dnf f-op2 "opcode" () 4 4)
224 (define-normal-insn-enum insn-op2 "insn op enums" () OP2_ f-op2
225 ( "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ))
226 (dnop bcond2 "branch condition opcode" () h-branchcond f-op2)
228 (dnf f-op2a "opcode" () 4 3)
229 (define-normal-insn-enum insn-op2a "insn op enums" () OP2A_ f-op2a
230 ( "0" "2" "4" "6" "8" "A" "C" "E" ))
232 (dnf f-op2m "opcode" () 7 1)
233 (define-normal-insn-enum insn-op2m "insn op enums" () OP2M_ f-op2m
235 (dnop ws2 "word size opcode" () h-wordsize f-op2m)
237 (dnf f-op3 "opcode" () 8 4)
238 (define-normal-insn-enum insn-op3 "insn op enums" () OP3_ f-op3
239 ( "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ))
241 (dnf f-op3a "opcode" () 8 2)
242 (define-normal-insn-enum insn-op3a "insn op enums" () OP3A_ f-op3a
245 (dnf f-op3b "opcode" () 8 3)
246 (define-normal-insn-enum insn-op3b "insn op enums" () OP3B_ f-op3b
247 ( "0" "2" "4" "6" "8" "A" "C" "E" ))
249 (dnf f-op4 "opcode" () 12 4)
250 (define-normal-insn-enum insn-op4 "insn op enums" () OP4_ f-op4
251 ( "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ))
253 (dnf f-op4m "opcode" () 12 1)
254 (define-normal-insn-enum insn-op4m "insn op enums" () OP4M_ f-op4m
257 (dnf f-op4b "opcode" () 15 1)
258 (define-normal-insn-enum insn-op4b "insn op enums" () OP4B_ f-op4b
261 (dnf f-op5 "opcode" () 16 4)
262 (define-normal-insn-enum insn-op5 "insn op enums" () OP5_ f-op5
263 ( "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ))
264 (dnop bcond5 "branch condition opcode" () h-branchcond f-op5)
266 (dnf f-op5a "opcode" () 16 1)
267 (define-normal-insn-enum insn-op5a "insn op enums" () OP5A_ f-op5a
270 ; The whole first word
271 (dnf f-op "opcode" () 0 16)
275 (dnf f-imm2 "2 bit unsigned" () 10 2)
276 (dnop imm2 "2 bit unsigned immediate" () h-uint f-imm2)
278 (dnf f-imm3 "3 bit unsigned" () 4 3)
279 (dnop imm3 "3 bit unsigned immediate" () h-uint f-imm3)
280 (dnf f-imm3b "3 bit unsigned for bit tests" () 17 3)
281 (dnop imm3b "3 bit unsigned immediate for bit tests" () h-uint f-imm3b)
283 (dnf f-imm4 "4 bit unsigned" () 8 4)
286 (comment "4 bit unsigned immediate")
290 (handlers (parse "small_immediate"))
293 (dnf f-imm8 "8 bit unsigned" () 8 8)
294 (dnop imm8 "8 bit unsigned immediate" () h-uint f-imm8)
297 (comment "8 bit unsigned immediate")
301 (handlers (parse "small_immediate"))
306 (comment "12 bit signed")
312 (dnop imm12 "12 bit signed immediate" () h-sint f-imm12)
314 (dnf f-imm16 "16 bit" (SIGN-OPT) 16 16)
317 (comment "16 bit immediate")
321 (handlers (parse "immediate16"))
324 (dnf f-lmem8 "8 bit unsigned low memory" (ABS-ADDR) 8 8)
327 (comment "8 bit unsigned immediate low memory")
331 (handlers (parse "mem8"))
335 (comment "8 bit unsigned high memory")
340 (encode (value pc) (sub HI value #x7F00))
341 (decode (value pc) (add HI value #x7F00))
345 (comment "8 bit unsigned immediate high memory")
349 (handlers (parse "mem8"))
354 (comment "8 bit relative address for 2-byte instruction")
359 (encode (value pc) (sub SI value (add SI pc 2)))
360 (decode (value pc) (add SI value (add SI pc 2)))
362 (dnop rel8-2 "8 bit relative address" () h-uint f-rel8-2)
366 (comment "8 bit relative address for 4-byte instruction")
371 (encode (value pc) (sub SI value (add SI pc 4)))
372 (decode (value pc) (add SI value (add SI pc 4)))
374 (dnop rel8-4 "8 bit relative address" () h-uint f-rel8-4)
378 (comment "12 bit relative address")
383 (encode (value pc) (sub SI value (add SI pc 4)))
384 (decode (value pc) (add SI value (add SI pc 4)))
386 (dnop rel12 "12 bit relative address" () h-uint f-rel12)
390 (comment "12 bit relative address")
395 (encode (value pc) (sra SI (sub SI value (add SI pc 2)) 1))
396 (decode (value pc) (add SI (mul value 2) (add SI pc 2)))
398 (dnop rel12a "12 bit relative address" () h-uint f-rel12a)
400 (dnf f-abs24-1 "abs24 low part" () 8 8)
401 (dnf f-abs24-2 "abs24 high part" () 16 16)
404 (comment "Absolute address for jmpf instruction")
407 (subfields f-abs24-1 f-abs24-2)
409 (set (ifield f-abs24-1) (and (ifield f-abs24) #xFF))
410 (set (ifield f-abs24-2) (srl (ifield f-abs24) 8))))
411 (extract (set (ifield f-abs24) (or (sll (ifield f-abs24-2) 8) f-abs24-1)))
413 (dnop abs24 "24 bit absolute address" () h-uint f-abs24)
415 ; Names for registers
416 (dnop psw "program status word" (SEM-ONLY) h-gr 14)
417 (dnop Rpsw "N0-N3 of the program status word" (SEM-ONLY) h-Rpsw f-nil)
418 (dnop sp "stack pointer" (SEM-ONLY) h-gr 15)
419 (dnop R0 "R0" (SEM-ONLY) h-gr 0)
420 (dnop R1 "R1" (SEM-ONLY) h-gr 1)
421 (dnop R2 "R2" (SEM-ONLY) h-gr 2)
422 (dnop R8 "R8" (SEM-ONLY) h-gr 8)
426 ; THe Z8, Z16, PT, and S flags of the PSW.
427 (define-pmacro (basic-psw value ws)
428 (or (or (zflag (and value #xFF))
429 (sll HI (zflag HI value) 1))
430 (or (sll HI (c-call BI "parity" value) 5)
431 (sll HI (nflag QI (srl value (mul ws 8))) 6))))
434 ; Update the PSW for destination register Rd, set Rd to value.
435 (define-pmacro (set-psw Rd index value ws)
436 (sequence ((HI nvalue))
438 (set (reg HI h-gr index) nvalue)
439 (set psw (or (and psw #x0F9C)
441 (basic-psw nvalue ws))))))
443 ; Update the PSW for destination register Rd.
444 (define-pmacro (set-psw-nowrite index value ws)
445 (sequence ((HI nvalue))
447 (set psw (or (and psw #x0F9C)
449 (basic-psw nvalue ws))))))
451 ; Update the PSW for destination non-register dest, set dest to value.
452 (define-pmacro (set-mem-psw dest value ws)
453 (sequence ((HI nvalue))
455 (set psw (or (and psw #xFF9C)
456 (basic-psw nvalue ws)))
459 ; Update the PSW as with set-psw, but also set the carry flag.
460 (define-pmacro (set-psw-carry Rd index value carry ws)
461 (sequence ((HI nvalue) (HI newpsw))
463 (set newpsw (or (or (and psw #x0F98)
464 (sll (and carry #x1) 2))
466 (basic-psw nvalue ws))))
467 (set (reg HI h-gr index) nvalue)
471 ; The all-purpose addition operation.
472 (define-pmacro (set-psw-add Rd index a b c)
473 (sequence ((HI value) (HI newpsw))
474 (set value (addc a b c))
475 (set newpsw (or (or (and psw #x0F80)
477 (or (or (sll HI (add-oflag HI a b c) 4)
478 (sll HI (add-cflag HI a b c) 2))
479 (or (and (srl HI (addc HI (and a #xF) (and b #xF) c)
482 (set (reg HI h-gr index) value)
486 ; Set the PSW for a subtraction of a-b into Rd, but don't actually
488 (define-pmacro (set-psw-cmp Rd index a b)
489 (sequence ((HI value))
490 (set value (sub a b))
491 (set psw (or (or (and psw #x0F80)
493 (or (or (sll HI (sub-oflag HI a b 0) 4)
494 (sll HI (sub-cflag HI a b 0) 2))
495 (or (and (srl HI (sub HI (and a #xF) (and b #xF))
499 ; Likewise, for subtraction
500 ; (this chip has a borrow for subtraction, rather than
501 ; just using a carry for both).
502 (define-pmacro (set-psw-sub Rd index a b c)
503 (sequence ((HI value) (HI newpsw))
504 (set value (subc a b c))
505 (set newpsw (or (or (and psw #x0F80)
507 (or (or (sll HI (sub-oflag HI a b c) 4)
508 (sll HI (sub-cflag HI a b c) 2))
509 (or (and (srl HI (subc HI (and a #xF) (and b #xF) c)
512 (set (reg HI h-gr index) value)
516 ; A 17-bit rotate-left operation
517 (define-pmacro (set-psw-rotate17 Rd index src c rot)
518 (sequence ((SI tmpfoo))
519 (set tmpfoo (or (or (and (sll SI src 15) #x7FFE0000)
523 (set tmpfoo (rol tmpfoo (and rot #x1F)))
524 (set-psw-carry (reg HI h-gr index) index (trunc HI tmpfoo) (and (srl tmpfoo 16) 1) 1)))
526 ; A 17-bit rotate-right operation
527 (define-pmacro (set-psw-rrotate17 Rd index src c rot)
528 (sequence ((SI tmpfoo))
529 (set tmpfoo (or (or (and (sll SI src 17) #xFFFE0000)
532 (set tmpfoo (ror tmpfoo (and rot #x0F)))
533 (set-psw-carry (reg HI h-gr index) index (trunc HI tmpfoo) (and (srl tmpfoo 16) 1) 1)))
538 (define-pmacro (alignfix-mem where)
539 (mem HI (and where #xFFFE)))
541 (define-pmacro (set-alignfix-mem where what)
542 (set (mem HI (and where #xFFFE)) what))
544 (define-pmacro (alignfix-mem-far where)
545 (mem HI (and where #xFFFFFFFE)))
547 (define-pmacro (set-alignfix-mem-far where what)
548 (set (mem HI (and where #xFFFFFFFE)) what))
551 "Move immediate to low memory"
553 ("mov$ws2 $lmem8,#$imm16")
554 (+ OP1_7 OP2A_8 ws2 lmem8 imm16)
556 (set-mem-psw (mem HI (and lmem8 #xFFFE)) imm16 ws2)
557 (set-mem-psw (mem QI lmem8) (and imm16 #xFF) ws2))
561 "Move immediate to high memory"
563 ("mov$ws2 $hmem8,#$imm16")
564 (+ OP1_7 OP2A_A ws2 hmem8 imm16)
566 (set-mem-psw (mem HI (and hmem8 #xFFFE)) imm16 ws2)
567 (set-mem-psw (mem QI hmem8) (and imm16 #xFF) ws2))
572 "Move low memory to register"
574 ("mov$ws2 $Rm,$lmem8")
575 (+ OP1_8 Rm ws2 lmem8)
577 (set-psw Rm (index-of Rm) (alignfix-mem lmem8) ws2)
578 (set-psw Rm (index-of Rm) (mem QI lmem8) ws2))
582 "Move high memory to register"
584 ("mov$ws2 $Rm,$hmem8")
585 (+ OP1_A Rm ws2 hmem8)
587 (set-psw Rm (index-of Rm) (alignfix-mem hmem8) ws2)
588 (set-psw Rm (index-of Rm) (mem QI hmem8) ws2))
593 "Move low memory register to byte"
595 ("mov$ws2 $lmem8,$Rm")
596 (+ OP1_9 Rm ws2 lmem8)
598 (set-mem-psw (mem HI (and lmem8 #xFFFE)) Rm ws2)
599 (set-mem-psw (mem QI lmem8) Rm ws2))
603 "Move high memory register to byte"
605 ("mov$ws2 $hmem8,$Rm")
606 (+ OP1_B Rm ws2 hmem8)
608 (set-mem-psw (mem HI (and hmem8 #xFFFE)) Rm ws2)
609 (set-mem-psw (mem QI hmem8) Rm ws2))
614 "Move memory addressed by register to register"
616 ("mov$ws2 $Rdm,($Rs)")
617 (+ OP1_7 OP2A_0 ws2 Rs OP4M_0 Rdm)
619 (set-psw Rdm (index-of Rdm) (alignfix-mem Rs) ws2)
620 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI Rs)) ws2))
625 "Move memory addressed by postincrement register to register"
627 ("mov$ws2 $Rdm,($Rs++)")
628 (+ OP1_6 OP2A_0 ws2 Rs OP4M_0 Rdm)
631 (set-psw Rdm (index-of Rdm) (alignfix-mem Rs) ws2)
632 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI Rs)) ws2))
633 (set Rs (add Rs (add 1 ws2))))
638 "Move memory addressed by predecrement register to register"
640 ("mov$ws2 $Rdm,(--$Rs)")
641 (+ OP1_6 OP2A_8 ws2 Rs OP4M_0 Rdm)
643 (set Rs (sub Rs (add 1 ws2)))
645 (set-psw Rdm (index-of Rdm) (alignfix-mem Rs) ws2)
646 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI Rs)) ws2)))
651 "Move register to memory addressed by register"
653 ("mov$ws2 ($Rs),$Rdm")
654 (+ OP1_7 OP2A_2 ws2 Rs OP4M_0 Rdm)
657 (set-alignfix-mem Rs Rdm)
658 (set (mem QI Rs) Rdm))
659 (set-psw-nowrite (index-of Rdm) Rdm ws2))
664 "Move register to memory addressed by postincrement register"
666 ("mov$ws2 ($Rs++),$Rdm")
667 (+ OP1_6 OP2A_2 ws2 Rs OP4M_0 Rdm)
670 (set-alignfix-mem Rs Rdm)
671 (set (mem QI Rs) Rdm))
672 (set-psw-nowrite (index-of Rdm) Rdm ws2)
673 (set Rs (add Rs (add ws2 1))))
678 "Move register to memory addressed by predecrement register"
680 ("mov$ws2 (--$Rs),$Rdm")
681 (+ OP1_6 OP2A_A ws2 Rs OP4M_0 Rdm)
683 (set Rs (sub Rs (add ws2 1)))
684 (set-psw-nowrite (index-of Rdm) Rdm ws2)
686 (set-alignfix-mem Rs Rdm)
687 (set (mem QI Rs) Rdm)))
692 "Move memory addressed by indexed register to register"
694 ("mov$ws2 $Rdm,($Rs,$imm12)")
695 (+ OP1_7 OP2A_0 ws2 Rs OP4M_1 Rdm OP5_0 imm12)
697 (set-psw Rdm (index-of Rdm) (alignfix-mem (add Rs imm12)) ws2)
698 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add Rs imm12))) ws2))
702 (dni movgrgriipostinc
703 "Move memory addressed by indexed register postincrement to register"
705 ("mov$ws2 $Rdm,($Rs++,$imm12)")
706 (+ OP1_6 OP2A_0 ws2 Rs OP4M_1 Rdm OP5_0 imm12)
709 (set-psw Rdm (index-of Rdm) (alignfix-mem (add Rs imm12)) ws2)
710 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add Rs imm12))) ws2))
711 (set Rs (add Rs (add ws2 1))))
716 "Move memory addressed by indexed register predecrement to register"
718 ("mov$ws2 $Rdm,(--$Rs,$imm12)")
719 (+ OP1_6 OP2A_8 ws2 Rs OP4M_1 Rdm OP5_0 imm12)
721 (set Rs (sub Rs (add ws2 1)))
723 (set-psw Rdm (index-of Rdm) (alignfix-mem (add Rs imm12)) ws2)
724 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add Rs imm12))) ws2)))
729 "Move register to memory addressed by indexed register"
731 ("mov$ws2 ($Rs,$imm12),$Rdm")
732 (+ OP1_7 OP2A_2 ws2 Rs OP4M_1 Rdm OP5_0 imm12)
735 (set-alignfix-mem (add Rs imm12) Rdm)
736 (set (mem QI (add Rs imm12)) Rdm))
737 (set-psw-nowrite (index-of Rdm) Rdm ws2))
741 (dni movgriipostincgr
742 "Move register to memory addressed by indexed register postincrement"
744 ("mov$ws2 ($Rs++,$imm12),$Rdm")
745 (+ OP1_6 OP2A_2 ws2 Rs OP4M_1 Rdm OP5_0 imm12)
748 (set-alignfix-mem (add Rs imm12) Rdm)
749 (set (mem QI (add Rs imm12)) Rdm))
750 (set-psw-nowrite (index-of Rdm) Rdm ws2)
751 (set Rs (add Rs (add ws2 1))))
756 "Move register to memory addressed by indexed register predecrement"
758 ("mov$ws2 (--$Rs,$imm12),$Rdm")
759 (+ OP1_6 OP2A_A ws2 Rs OP4M_1 Rdm OP5_0 imm12)
761 (set Rs (sub Rs (add ws2 1)))
762 (set-psw-nowrite (index-of Rdm) Rdm ws2)
764 (set-alignfix-mem (add Rs imm12) Rdm)
765 (set (mem QI (add Rs imm12)) Rdm)))
770 "Move general register to general register"
773 (+ OP1_4 OP2_6 Rs Rd)
774 (set-psw Rd (index-of Rd) Rs 1)
779 "Move 8-bit immediate"
786 "Move 8-bit immediate"
790 (set-psw (reg HI h-gr Rpsw) Rpsw imm8 1)
795 "Move 8-bit immediate to general register"
797 ("mov $Rm,#$imm8small")
798 (emit movwgrimm8 Rm imm8small)
802 "Move 8-bit immediate to general register"
804 ("mov.w $Rm,#$imm8small")
805 (+ OP1_2 Rm OP2M_1 imm8small)
806 (set-psw Rm (index-of Rm) imm8small 1)
811 "Move 16-bit immediate to general register"
814 (emit movwgrimm16 Rd imm16)
818 "Move 16-bit immediate to general register"
820 ("mov.w $Rd,#$imm16")
821 (+ OP1_3 OP2_1 OP3_3 Rd imm16)
822 (set-psw Rd (index-of Rd) imm16 1)
827 "Move 8 low bits to general register"
830 (+ OP1_3 OP2_0 OP3_C Rd)
831 (set-psw Rd (index-of Rd) (or (and Rd #xFF00) (and (reg HI h-gr Rpsw) #xFF)) 0)
836 "Move 8 high bits to general register"
839 (+ OP1_3 OP2_0 OP3_D Rd)
840 (set-psw Rd (index-of Rd) (or (and Rd #x00FF) (and (reg HI h-gr Rpsw) #xFF00)) 1)
845 "Move far memory addressed by register to register"
847 ("movf$ws2 $Rdm,($Rs)")
848 (+ OP1_7 OP2A_4 ws2 Rs OP4M_0 Rdm)
850 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (or (sll SI R8 16) Rs)) ws2)
851 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (or (sll SI R8 16) Rs))) ws2))
855 (dni movfgrgripostinc
856 "Move far memory addressed by postincrement register to register"
858 ("movf$ws2 $Rdm,($Rs++)")
859 (+ OP1_6 OP2A_4 ws2 Rs OP4M_0 Rdm)
862 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (join SI HI R8 Rs)) ws2)
863 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (join SI HI R8 Rs))) ws2))
864 (set Rs (add Rs (add ws2 1))))
869 "Move far memory addressed by predecrement register to register"
871 ("movf$ws2 $Rdm,(--$Rs)")
872 (+ OP1_6 OP2A_C ws2 Rs OP4M_0 Rdm)
874 (set Rs (sub Rs (add ws2 1)))
876 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (join SI HI R8 Rs)) ws2)
877 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (join SI HI R8 Rs))) ws2)))
882 "Move far register to memory addressed by register"
884 ("movf$ws2 ($Rs),$Rdm")
885 (+ OP1_7 OP2A_6 ws2 Rs OP4M_0 Rdm)
888 (set-alignfix-mem-far (join SI HI R8 Rs) Rdm)
889 (set (mem QI (join SI HI R8 Rs)) Rdm))
890 (set-psw-nowrite (index-of Rdm) Rdm ws2))
894 (dni movfgripostincgr
895 "Move far register to memory addressed by postincrement register"
897 ("movf$ws2 ($Rs++),$Rdm")
898 (+ OP1_6 OP2A_6 ws2 Rs OP4M_0 Rdm)
901 (set-alignfix-mem-far (join SI HI R8 Rs) Rdm)
902 (set (mem QI (join SI HI R8 Rs)) Rdm))
903 (set-psw-nowrite (index-of Rdm) Rdm ws2)
904 (set Rs (add Rs (add ws2 1))))
909 "Move far register to memory addressed by predecrement register"
911 ("movf$ws2 (--$Rs),$Rdm")
912 (+ OP1_6 OP2A_E ws2 Rs OP4M_0 Rdm)
914 (set-psw-nowrite (index-of Rdm) Rdm ws2)
915 (set Rs (sub Rs (add ws2 1)))
917 (set-alignfix-mem-far (join SI HI R8 Rs) Rdm)
918 (set (mem QI (join SI HI R8 Rs)) Rdm)))
923 "Move far memory addressed by indexed register to register"
925 ("movf$ws2 $Rdm,($Rb,$Rs,$imm12)")
926 (+ OP1_7 OP2A_4 ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
928 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (add (join SI HI Rb Rs) imm12)) ws2)
929 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add (join SI HI Rb Rs) imm12))) ws2))
933 (dni movfgrgriipostinc
934 "Move far memory addressed by indexed register postincrement to register"
936 ("movf$ws2 $Rdm,($Rb,$Rs++,$imm12)")
937 (+ OP1_6 OP2A_4 ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
940 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (add (join SI HI Rb Rs) imm12)) ws2)
941 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add (join SI HI Rb Rs) imm12))) ws2))
942 (set Rs (add Rs (add ws2 1)))
943 ; Note - despite the XStormy16 ISA documentation the
944 ; addition *is* propogated into the base register.
945 (if (eq Rs 0) (set Rb (add Rb 1)))
950 (dni movfgrgriipredec
951 "Move far memory addressed by indexed register predecrement to register"
953 ("movf$ws2 $Rdm,($Rb,--$Rs,$imm12)")
954 (+ OP1_6 OP2A_C ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
956 ; Note - despite the XStormy16 ISA documentation the
957 ; subtraction *is* propogated into the base register.
958 (if (eq Rs 0) (set Rb (sub Rb 1)))
959 (set Rs (sub Rs (add ws2 1)))
961 (set-psw Rdm (index-of Rdm) (alignfix-mem-far (add (join SI HI Rb Rs) imm12)) ws2)
962 (set-psw Rdm (index-of Rdm) (and #xFF (mem QI (add (join SI HI Rb Rs) imm12))) ws2)))
967 "Move far register to memory addressed by indexed register"
969 ("movf$ws2 ($Rb,$Rs,$imm12),$Rdm")
970 (+ OP1_7 OP2A_6 ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
973 (set (mem HI (and (add (join SI HI Rb Rs) imm12) #xFFFFFFFE))
975 (set (mem QI (add (join SI HI Rb Rs) imm12)) Rdm))
976 (set-psw-nowrite (index-of Rdm) Rdm ws2))
981 (dni movfgriipostincgr
982 "Move far register to memory addressed by indexed register postincrement"
984 ("movf$ws2 ($Rb,$Rs++,$imm12),$Rdm")
985 (+ OP1_6 OP2A_6 ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
988 (set (mem HI (and (add (join SI HI Rb Rs) imm12) #xFFFFFFFE)) Rdm)
989 (set (mem QI (add (join SI HI Rb Rs) imm12)) Rdm))
990 (set-psw-nowrite (index-of Rdm) Rdm ws2)
991 (set Rs (add Rs (add ws2 1)))
992 ; Note - despite the XStormy16 ISA documentation the
993 ; addition *is* propogated into the base register.
994 (if (eq Rs 0) (set Rb (add Rb 1)))
999 (dni movfgriipredecgr
1000 "Move far register to memory addressed by indexed register predecrement"
1002 ("movf$ws2 ($Rb,--$Rs,$imm12),$Rdm")
1003 (+ OP1_6 OP2A_E ws2 Rs OP4M_1 Rdm OP5A_0 Rb imm12)
1005 ; Note - despite the XStormy16 ISA documentation the
1006 ; subtraction *is* propogated into the base register.
1007 (if (eq Rs 0) (set Rb (sub Rb 1)))
1008 (set Rs (sub Rs (add ws2 1)))
1009 (set-psw-nowrite (index-of Rdm) Rdm ws2)
1011 (set (mem HI (and (add (join SI HI Rb Rs) imm12) #xFFFFFFFE)) Rdm)
1012 (set (mem QI (add (join SI HI Rb Rs) imm12)) Rdm)))
1017 "Mask insert controlled by general register"
1020 (+ OP1_3 OP2_3 Rs Rd)
1021 (set-psw Rd (index-of Rd) (or HI (and HI Rd (inv HI Rs)) (and (reg HI h-gr Rpsw) Rs)) 1)
1026 "Mask insert controlled by immediate value"
1028 ("mask $Rd,#$imm16")
1029 (+ OP1_3 OP2_0 OP3_E Rd imm16)
1030 (set-psw Rd (index-of Rd) (or (and Rd (inv imm16)) (and (reg HI h-gr Rpsw) imm16)) 1)
1039 (+ OP1_0 OP2_0 OP3_8 Rd)
1041 (set (mem HI sp) Rd)
1042 (set sp (add sp 2)))
1047 "Pop into a register"
1050 (+ OP1_0 OP2_0 OP3_9 Rd)
1052 (set sp (add sp -2))
1053 (set Rd (mem HI sp)))
1062 (+ OP1_3 OP2_0 OP3_9 Rd)
1063 (set-psw Rd (index-of Rd) (or (or (and (sll Rd 4) #xF0)
1064 (and (srl Rd 4) #x0F))
1073 (+ OP1_3 OP2_0 OP3_8 Rd)
1074 (set-psw Rd (index-of Rd) (or (sll Rd 8) (srl Rd 8)) 1)
1082 (+ OP1_3 OP2_2 Rs Rd)
1083 (sequence ((HI foo))
1086 (set-psw Rd (index-of Rd) foo 1))
1090 ; Logical Operations
1092 "AND general register with general register"
1095 (+ OP1_4 OP2_0 Rs Rd)
1096 (set-psw Rd (index-of Rd) (and Rd Rs) 1)
1101 "AND with 8-bit immediate"
1104 (+ OP1_4 OP2_1 imm8)
1105 (set-psw (reg HI h-gr Rpsw) Rpsw (and (reg HI h-gr Rpsw) imm8) 1)
1110 "AND general register with 16-bit immediate"
1113 (+ OP1_3 OP2_1 OP3_0 Rd imm16)
1114 (set-psw Rd (index-of Rd) (and Rd imm16) 1)
1119 "OR general register with general register"
1122 (+ OP1_4 OP2_2 Rs Rd)
1123 (set-psw Rd (index-of Rd) (or Rd Rs) 1)
1128 "OR with 8-bit immediate"
1131 (+ OP1_4 OP2_3 imm8)
1132 (set-psw (reg HI h-gr Rpsw) Rpsw (or (reg HI h-gr Rpsw) imm8) 1)
1137 "OR general register with 16-bit immediate"
1140 (+ OP1_3 OP2_1 OP3_1 Rd imm16)
1141 (set-psw Rd (index-of Rd) (or Rd imm16) 1)
1146 "XOR general register with general register"
1149 (+ OP1_4 OP2_4 Rs Rd)
1150 (set-psw Rd (index-of Rd) (xor Rd Rs) 1)
1155 "XOR with 8-bit immediate"
1158 (+ OP1_4 OP2_5 imm8)
1159 (set-psw (reg HI h-gr Rpsw) Rpsw (xor (reg HI h-gr Rpsw) imm8) 1)
1164 "XOR general register with 16-bit immediate"
1167 (+ OP1_3 OP2_1 OP3_2 Rd imm16)
1168 (set-psw Rd (index-of Rd) (xor Rd imm16) 1)
1173 "NOT general register"
1176 (+ OP1_3 OP2_0 OP3_B Rd)
1177 (set-psw Rd (index-of Rd) (inv Rd) 1)
1181 ; Arithmetic operations
1183 "ADD general register to general register"
1186 (+ OP1_4 OP2_9 Rs Rd)
1187 (set-psw-add Rd (index-of Rd) Rd Rs 0)
1192 "ADD 4-bit immediate to general register"
1195 (+ OP1_5 OP2_1 imm4 Rd)
1196 (set-psw-add Rd (index-of Rd) Rd imm4 0)
1201 "ADD 8-bit immediate"
1204 (+ OP1_5 OP2_9 imm8)
1205 (set-psw-add (reg HI h-gr Rpsw) Rpsw (reg HI h-gr Rpsw) imm8 0)
1210 "ADD 16-bit immediate to general register"
1213 (+ OP1_3 OP2_1 OP3_4 Rd imm16)
1214 (set-psw-add Rd (index-of Rd) Rd imm16 0)
1219 "ADD carry and general register to general register"
1222 (+ OP1_4 OP2_B Rs Rd)
1223 (set-psw-add Rd (index-of Rd) Rd Rs psw-cy)
1228 "ADD carry and 4-bit immediate to general register"
1231 (+ OP1_5 OP2_3 imm4 Rd)
1232 (set-psw-add Rd (index-of Rd) Rd imm4 psw-cy)
1237 "ADD carry and 8-bit immediate"
1240 (+ OP1_5 OP2_B imm8)
1241 (set-psw-add (reg HI h-gr Rpsw) Rpsw (reg HI h-gr Rpsw) imm8 psw-cy)
1246 "ADD carry and 16-bit immediate to general register"
1249 (+ OP1_3 OP2_1 OP3_5 Rd imm16)
1250 (set-psw-add Rd (index-of Rd) Rd imm16 psw-cy)
1255 "SUB general register from general register"
1258 (+ OP1_4 OP2_D Rs Rd)
1259 (set-psw-sub Rd (index-of Rd) Rd Rs 0)
1264 "SUB 4-bit immediate from general register"
1267 (+ OP1_5 OP2_5 imm4 Rd)
1268 (set-psw-sub Rd (index-of Rd) Rd imm4 0)
1273 "SUB 8-bit immediate"
1276 (+ OP1_5 OP2_D imm8)
1277 (set-psw-sub (reg HI h-gr Rpsw) Rpsw (reg HI h-gr Rpsw) imm8 0)
1282 "SUB 16-bit immediate from general register"
1285 (+ OP1_3 OP2_1 OP3_6 Rd imm16)
1286 (set-psw-sub Rd (index-of Rd) Rd imm16 0)
1291 "SUB carry and general register from general register"
1294 (+ OP1_4 OP2_F Rs Rd)
1295 (set-psw-sub Rd (index-of Rd) Rd Rs psw-cy)
1300 "SUB carry and 4-bit immediate from general register"
1303 (+ OP1_5 OP2_7 imm4 Rd)
1304 (set-psw-sub Rd (index-of Rd) Rd imm4 psw-cy)
1309 "SUB carry and 8-bit immediate"
1312 (+ OP1_5 OP2_F imm8)
1313 (set-psw-sub (reg HI h-gr Rpsw) Rpsw (reg HI h-gr Rpsw) imm8 psw-cy)
1318 "SUB carry and 16-bit immediate from general register"
1321 (+ OP1_3 OP2_1 OP3_7 Rd imm16)
1322 (set-psw-sub Rd (index-of Rd) Rd imm16 psw-cy)
1327 "Increment general register"
1330 (emit incgrimm2 Rd (imm2 0))
1334 "Increment general register by 2-bit immediate"
1337 (+ OP1_3 OP2_0 OP3A_0 imm2 Rd)
1338 (set-psw Rd (index-of Rd) (add Rd (add imm2 1)) 1)
1343 "Decrement general register"
1346 (emit decgrimm2 Rd (imm2 0))
1350 "Decrement general register by 2-bit immediate"
1353 (+ OP1_3 OP2_0 OP3A_1 imm2 Rd)
1354 (set-psw Rd (index-of Rd) (sub Rd (add imm2 1)) 1)
1360 "Rotate right general register by general register"
1363 (+ OP1_3 OP2_8 Rs Rd)
1364 (set-psw-rrotate17 Rd (index-of Rd) Rd psw-cy Rs)
1369 "Rotate right general register by immediate"
1372 (+ OP1_3 OP2_9 imm4 Rd)
1373 (set-psw-rrotate17 Rd (index-of Rd) Rd psw-cy imm4)
1378 "Rotate left general register by general register"
1381 (+ OP1_3 OP2_A Rs Rd)
1382 (set-psw-rotate17 Rd (index-of Rd) Rd psw-cy (and Rs #xF))
1387 "Rotate left general register by immediate"
1390 (+ OP1_3 OP2_B imm4 Rd)
1391 (set-psw-rotate17 Rd (index-of Rd) Rd psw-cy imm4)
1396 "Shift right general register by general register"
1399 (+ OP1_3 OP2_C Rs Rd)
1400 (set-psw-carry Rd (index-of Rd)
1401 (srl Rd (and Rs #xF))
1402 (and SI (if SI (eq (and Rs #xF) 0)
1404 (srl Rd (sub (and Rs #xF) 1)))
1410 "Shift right general register by immediate"
1413 (+ OP1_3 OP2_D imm4 Rd)
1414 (set-psw-carry Rd (index-of Rd)
1416 (and SI (if SI (eq imm4 0)
1418 (srl Rd (sub imm4 1)))
1424 "Shift left general register by general register"
1427 (+ OP1_3 OP2_E Rs Rd)
1428 (set-psw-carry Rd (index-of Rd)
1429 (sll Rd (and Rs #xF))
1430 (srl SI (if SI (eq (and Rs #xF) 0)
1432 (sll Rd (sub (and Rs #xF) 1)))
1438 "Shift left general register by immediate"
1441 (+ OP1_3 OP2_F imm4 Rd)
1442 (set-psw-carry Rd (index-of Rd)
1444 (srl SI (if SI (eq imm4 0)
1446 (sll Rd (sub imm4 1)))
1452 "Arithmetic shift right general register by general register"
1455 (+ OP1_3 OP2_6 Rs Rd)
1456 (set-psw-carry Rd (index-of Rd)
1457 (sra HI Rd (and Rs #xF))
1458 (and SI (if SI (eq (and Rs #xF) 0)
1460 (srl Rd (sub (and Rs #xF) 1)))
1466 "Arithmetic shift right general register by immediate"
1469 (+ OP1_3 OP2_7 imm4 Rd)
1470 (set-psw-carry Rd (index-of Rd)
1472 (and SI (if SI (eq imm4 0)
1474 (srl Rd (sub imm4 1)))
1479 ; Bitwise operations
1481 "Set bit in general register by immediate"
1484 (+ OP1_0 OP2_9 imm4 Rd)
1485 (set-psw Rd (index-of Rd) (or Rd (sll 1 imm4)) 1)
1490 "Set bit in general register by general register"
1493 (+ OP1_0 OP2_B Rs Rd)
1494 (set-psw Rd (index-of Rd) (or Rd (sll 1 (and Rs #xF))) 1)
1499 "Set bit in low memory by immediate"
1501 ("set1 $lmem8,#$imm3")
1502 (+ OP1_E imm3 OP2M_1 lmem8)
1503 (set-mem-psw (mem QI lmem8) (or (mem QI lmem8) (sll 1 imm3)) 0)
1507 "Set bit in high memory by immediate"
1509 ("set1 $hmem8,#$imm3")
1510 (+ OP1_F imm3 OP2M_1 hmem8)
1511 (set-mem-psw (mem QI hmem8) (or (mem QI hmem8) (sll 1 imm3)) 0)
1516 "Clear bit in general register by immediate"
1519 (+ OP1_0 OP2_8 imm4 Rd)
1520 (set-psw Rd (index-of Rd) (and Rd (inv (sll 1 imm4))) 1)
1525 "Clear bit in general register by general register"
1528 (+ OP1_0 OP2_A Rs Rd)
1529 (set-psw Rd (index-of Rd) (and Rd (inv (sll 1 (and Rs #xF)))) 1)
1534 "Clear bit in low memory"
1536 ("clr1 $lmem8,#$imm3")
1537 (+ OP1_E imm3 OP2M_0 lmem8)
1538 (set-mem-psw (mem QI lmem8) (and (mem QI lmem8) (inv (sll 1 imm3))) 0)
1542 "Clear bit in high memory"
1544 ("clr1 $hmem8,#$imm3")
1545 (+ OP1_F imm3 OP2M_0 hmem8)
1546 (set-mem-psw (mem QI hmem8) (and (mem QI hmem8) (inv (sll 1 imm3))) 0)
1553 "Sign-extend byte in general register"
1556 (+ OP1_3 OP2_0 OP3_A Rd)
1557 (set-psw Rd (index-of Rd) (ext HI (trunc QI Rd)) 1)
1562 "Reverse bit pattern in general register"
1565 (+ OP1_3 OP2_0 OP3_F Rd)
1566 (set-psw Rd (index-of Rd)
1567 (or (sll (and Rd #x0001) 15)
1568 (or (sll (and Rd #x0002) 13)
1569 (or (sll (and Rd #x0004) 11)
1570 (or (sll (and Rd #x0008) 9)
1571 (or (sll (and Rd #x0010) 7)
1572 (or (sll (and Rd #x0020) 5)
1573 (or (sll (and Rd #x0040) 3)
1574 (or (sll (and Rd #x0080) 1)
1575 (or (srl (and Rd #x0100) 1)
1576 (or (srl (and Rd #x0200) 3)
1577 (or (srl (and Rd #x0400) 5)
1578 (or (srl (and Rd #x0800) 7)
1579 (or (srl (and Rd #x1000) 9)
1580 (or (srl (and Rd #x2000) 11)
1581 (or (srl (and Rd #x4000) 13)
1582 (srl (and Rd #x8000) 15))))))))))))))))
1587 ; Conditional Branches
1589 (define-pmacro (cbranch cond dest)
1590 (sequence ((BI tmp))
1592 ((0) (set tmp (not (xor psw-s psw-ov)))) ; ge
1593 ((1) (set tmp (not psw-cy))) ; nc
1594 ((2) (set tmp (xor psw-s psw-ov))) ; lt
1595 ((3) (set tmp psw-cy)) ; c
1596 ((4) (set tmp (not (or (xor psw-s psw-ov) psw-z16)))) ; gt
1597 ((5) (set tmp (not (or psw-cy psw-z16)))) ; hi
1598 ((6) (set tmp (or (xor psw-s psw-ov) psw-z16))) ; le
1599 ((7) (set tmp (or psw-cy psw-z16))) ; ls
1600 ((8) (set tmp (not psw-s))) ; pl
1601 ((9) (set tmp (not psw-ov))) ; nv
1602 ((10) (set tmp psw-s)) ; mi
1603 ((11) (set tmp psw-ov)) ; v
1604 ((12) (set tmp (not psw-z8))) ; nz.b
1605 ((13) (set tmp (not psw-z16))) ; nz
1606 ((14) (set tmp psw-z8)) ; z.b
1607 ((15) (set tmp psw-z16))) ; z
1608 (if tmp (set pc dest)))
1612 "Conditional branch comparing general register with general register"
1614 ("b$bcond5 $Rd,$Rs,$rel12")
1615 (+ OP1_0 OP2_D Rs Rd bcond5 rel12)
1617 (set-psw-cmp Rd (index-of Rd) Rd Rs)
1618 (cbranch bcond5 rel12))
1624 "Conditional branch comparing general register with 8-bit immediate"
1626 ("b$bcond5 $Rm,#$imm8,$rel12")
1627 (+ OP1_2 OP2M_0 Rm imm8 bcond5 rel12)
1629 (set-psw-cmp Rm (index-of Rm) Rm imm8)
1630 (cbranch bcond5 rel12))
1636 "Conditional branch comparing general register with 16-bit immediate"
1638 ("b$bcond2 Rx,#$imm16,${rel8-4}")
1639 (+ OP1_C bcond2 rel8-4 imm16)
1641 (set-psw-cmp (reg HI h-gr Rpsw) Rpsw (reg HI h-gr Rpsw) imm16)
1642 (cbranch bcond2 rel8-4))
1647 "Test bit in general register by immediate and branch if 0"
1649 ("bn $Rd,#$imm4,$rel12")
1650 (+ OP1_0 OP2_4 imm4 Rd OP5_0 rel12)
1652 (set Rpsw (index-of Rd))
1653 (if (eq (and Rd (sll 1 imm4)) 0)
1659 "Test bit in general register by general register and branch if 0"
1661 ("bn $Rd,$Rs,$rel12")
1662 (+ OP1_0 OP2_6 Rs Rd OP5_0 rel12)
1664 (set Rpsw (index-of Rd))
1665 (if (eq (and Rd (sll 1 Rs)) 0)
1671 "Test bit in memory by immediate and branch if 0"
1673 ("bn $lmem8,#$imm3b,$rel12")
1674 (+ OP1_7 OP2_C lmem8 OP5A_0 imm3b rel12)
1675 (if (eq (and (mem QI lmem8) (sll 1 imm3b)) 0)
1681 "Test bit in memory by immediate and branch if 0"
1683 ("bn $hmem8,#$imm3b,$rel12")
1684 (+ OP1_7 OP2_E hmem8 OP5A_0 imm3b rel12)
1685 (if (eq (and (mem QI hmem8) (sll 1 imm3b)) 0)
1691 "Test bit in general register by immediate and branch if 1"
1693 ("bp $Rd,#$imm4,$rel12")
1694 (+ OP1_0 OP2_5 imm4 Rd OP5_0 rel12)
1696 (set Rpsw (index-of Rd))
1697 (if (ne (and Rd (sll 1 imm4)) 0)
1703 "Test bit in general register by general register and branch if 1"
1705 ("bp $Rd,$Rs,$rel12")
1706 (+ OP1_0 OP2_7 Rs Rd OP5_0 rel12)
1708 (set Rpsw (index-of Rd))
1709 (if (ne (and Rd (sll 1 Rs)) 0)
1715 "Test bit in memory by immediate and branch if 1"
1717 ("bp $lmem8,#$imm3b,$rel12")
1718 (+ OP1_7 OP2_D lmem8 OP5A_0 imm3b rel12)
1719 (if (ne (and (mem QI lmem8) (sll 1 imm3b)) 0)
1725 "Test bit in memory by immediate and branch if 1"
1727 ("bp $hmem8,#$imm3b,$rel12")
1728 (+ OP1_7 OP2_F hmem8 OP5A_0 imm3b rel12)
1729 (if (ne (and (mem QI hmem8) (sll 1 imm3b)) 0)
1735 "Conditional branch on flag registers"
1737 ("b$bcond2 ${rel8-2}")
1738 (+ OP1_D bcond2 rel8-2)
1739 (cbranch bcond2 rel8-2)
1743 ; Unconditional Branching
1746 "Branch to register"
1749 (+ OP1_0 OP2_0 OP3_2 Rd)
1750 (set pc (add (add pc 2) Rd))
1758 (+ OP1_1 rel12a OP4B_0)
1767 (+ OP1_0 OP2_0 OP3B_4 Rbj Rd)
1768 (set pc (join SI HI Rbj Rd))
1776 (+ OP1_0 OP2_2 abs24)
1782 (define-pmacro (do-call dest ilen)
1784 (set (mem SI sp) (add pc ilen))
1789 "Call relative to general register"
1792 (+ OP1_0 OP2_0 OP3_1 Rd)
1793 (do-call (add Rd (add pc 2)) 2)
1798 "Call relative to immediate address"
1801 (+ OP1_1 rel12a OP4B_1)
1807 "Call to general registers"
1810 (+ OP1_0 OP2_0 OP3B_A Rbj Rd)
1811 (do-call (join SI HI Rbj Rd) 2)
1816 "Call far to absolute address"
1819 (+ OP1_0 OP2_1 abs24)
1824 (define-pmacro (do-calli dest ilen)
1826 (set (mem SI sp) (add pc ilen))
1827 (set (mem HI (add sp 4)) psw)
1832 "Call interrupt to general registers pc-relative"
1835 (+ OP1_0 OP2_0 OP3_3 Rd)
1836 (do-calli (add Rd (add pc 2)) 2)
1841 "Call interrupt to general registers"
1844 (+ OP1_0 OP2_0 OP3B_6 Rbj Rd)
1845 (do-calli (join SI HI Rbj Rd) 2)
1850 "Call interrupt far to absolute address"
1853 (+ OP1_0 OP2_3 abs24)
1858 ; Return instructions
1860 "Return from interrupt"
1866 (set pc (mem SI sp))
1867 (set psw (mem HI (add sp 4))))
1878 (set pc (mem SI sp)))
1882 ; Multiply and Divide instructions
1889 (sequence ((SI value))
1890 (set value (mul SI (and SI R0 #xFFFF) (and SI R2 #xFFFF)))
1891 (set psw (or (and psw #xFF9C)
1892 (basic-psw (trunc HI value) 1)))
1893 (set R0 (trunc HI value))
1894 (set R1 (trunc HI (srl value 16))))
1903 (set R1 (umod R0 R2))
1904 (set-mem-psw R0 (udiv R0 R2) 1))
1913 (set R1 (mod HI R0 R2))
1914 (set-mem-psw R0 (div HI R0 R2) 1))
1922 (sequence ((SI value))
1923 (set value (add SI (sll SI (and SI R1 #xffff) #x10) (and SI R0 #xffff)))
1924 (set R1 (mod SI value (ext SI (trunc HI R2))))
1925 (set-mem-psw R0 (div SI value (ext SI (trunc HI R2))) 1))
1933 (sequence ((SI value))
1934 (set value (add SI (sll SI (and SI R1 #xffff) #x10) (and SI R0 #xffff)))
1935 (set R1 (umod SI value R2))
1936 (set-mem-psw R0 (udiv SI value R2) 1))
1942 ; added per sanyo's req -- eq to nop for the moment, but can
1943 ; add function later
1944 (dni reset "reset" () ("reset") (+ (f-op #x000f)) (nop) ())
1946 (dni nop "nop" () ("nop") (+ (f-op #x0000)) (nop) ())
1948 (dni halt "halt" () ("halt") (+ (f-op #x0008)) (c-call VOID "do_halt") ())
1950 (dni hold "hold" () ("hold") (+ (f-op #x000A)) (c-call VOID "do_hold") ())
1952 (dni holdx "holdx" () ("holdx") (+ (f-op #x000B)) (c-call VOID "do_holdx") ())
1954 (dni brk "brk" () ("brk") (+ (f-op #x0005)) (c-call VOID "do_brk") ())
1956 ; An instruction for test instrumentation.
1957 ; Using a reserved opcode.
1959 "simulator system call"
1963 (c-call VOID "syscall")