1        # Used for all instructions that have a 3-address form
2	.macro TERNARY insn
3        # reg-reg
4        \insn   $r31, $r0, $r0
5        \insn   $r0, $r31, $r0
6        \insn   $r0, $r0, $r31
7        \insn   $r1, $r2, $r4
8        \insn   $r8, $r16, $r0
9
10        # immediate
11        \insn   $r31, $r0, -512
12        \insn   $r0, $r31, 0
13        \insn   $r0, $r31, 1
14        \insn   $r0, $r31, 511
15
16        # short and byte
17        \insn\().s $r0, $r31, $r1
18        \insn\().s $r0, $r31, 77
19        \insn\().b $r0, $r31, $r1
20        \insn\().b $r0, $r31, 77
21
22        .endm
23
24        .macro RegUImm insn
25        \insn   r0, r0, 0
26        \insn   r0, r0, 65535
27        \insn   r0, r31, 0
28        \insn   r0, r31, 65535
29        \insn   r31, r0, 0
30        \insn   r31, r0, 65535
31        .endm
32
33	.macro CMPOP insn
34        # reg-reg
35        \insn   $r0, $r0
36        \insn   $r31, $r0
37        \insn   $r0, $r31
38
39        # immediate
40        \insn   $r0, -512
41        \insn   $r31, 0
42        \insn   $r31, 1
43        \insn   $r31, 511
44
45        # short and byte
46        \insn\().s $r31, $r1
47        \insn\().s $r31, 77
48        \insn\().b $r31, $r1
49        \insn\().b $r31, 77
50
51        .endm
52
53        .section .data
54dalabel:
55        .long   0
56
57        .section .text
58pmlabel:
59
60        TERNARY add
61        TERNARY sub
62        TERNARY and
63        TERNARY or
64        TERNARY xor
65        TERNARY xnor
66        TERNARY ashl
67        TERNARY lshr
68        TERNARY ashr
69        TERNARY ror
70        TERNARY ldl
71        TERNARY bins
72        TERNARY bexts
73        TERNARY bextu
74        TERNARY flip
75
76        CMPOP   addcc
77        CMPOP   cmp
78        CMPOP   tst
79        CMPOP   btst
80
81        # LDI, STI, EXI
82        ldi.l   $r0,$r31,-128
83        ldi.l   $r31,$r0,127
84        ldi.s   $r0,$r31,-128
85        ldi.s   $r0,$r31,127
86        ldi.b   $r31,$r0,-128
87        ldi.b   $r31,$r0,127
88        sti.l   $r31,-128,$r0
89        sti.l   $r0,127,$r31
90        sti.s   $r31,-128,$r0
91        sti.s   $r31,127,$r0
92        sti.b   $r0,-128,$r31
93        sti.b   $r0,127,$r31
94        exi.l   $r0,$r31,-128
95        exi.l   $r31,$r0,127
96        exi.s   $r0,$r31,-128
97        exi.s   $r0,$r31,127
98        exi.b   $r31,$r0,-128
99        exi.b   $r31,$r0,127
100
101        # LPM, LPMI
102        lpm.l   $r0,pmlabel
103        lpm.s   $r16,pmlabel
104        lpm.b   $r31,pmlabel
105        lpmi.l  $r0,$r1,-128
106        lpmi.s  $r16,$r1,127
107        lpmi.b  $r31,$r1,-128
108
109        # JMP
110        jmp     pmlabel
111        jmpi    $r16
112        jmpx    31,$r28,1,pmlabel
113        jmpc    nz,pmlabel
114
115        # CALL
116        call    pmlabel
117        calli   $r16
118        callx   31,$r28,1,pmlabel
119        callc   nz,pmlabel
120
121        # PUSH, POP
122        push    $r0
123        push    $r16
124        push    $r31
125        pop     $r0
126        pop     $r16
127        pop     $r31
128
129        # LINK,UNLINK
130        link    $r0,0
131        link    $r16,65535
132        link    $r31,1017
133        unlink  $r0
134        unlink  $r16
135        unlink  $r31
136
137        # RETURN,RETI
138        return
139        reti
140
141        # LDA,STA,EXA
142        lda.l   $r0,dalabel
143        lda.s   $r16,dalabel
144        lda.b   $r31,dalabel
145        sta.l   dalabel,$r0
146        sta.s   dalabel,$r16
147        sta.b   dalabel,$r31
148        exa.l   $r0,dalabel
149        exa.s   $r16,dalabel
150        exa.b   $r31,dalabel
151
152        # LDK
153        ldk     $r0,-524288
154        ldk     $r0,524287
155        ldk     $r0,0
156
157        move    $r0,$r31
158        move    $r31,$r0
159
160        TERNARY udiv
161        TERNARY umod
162        TERNARY div
163        TERNARY mod
164        TERNARY strcmp
165        TERNARY memcpy
166        TERNARY memset
167        TERNARY mul
168        TERNARY muluh
169        TERNARY streamin
170        TERNARY streamini
171        TERNARY streamout
172        TERNARY streamouti
173
174        strlen.l $r0,$r31
175        strlen.l $r31,$r0
176        strlen.s $r0,$r31
177        strlen.s $r31,$r0
178        strlen.b $r0,$r31
179        strlen.b $r31,$r0
180        stpcpy.l $r0,$r31
181        stpcpy.l $r31,$r0
182        stpcpy.s $r0,$r31
183        stpcpy.s $r31,$r0
184        stpcpy.b $r0,$r31
185        stpcpy.b $r31,$r0
186