comparison test/tests/opcodes6809.pl @ 175:5e7f8e1ac99f

added tests to verify 6809 opcodes are correct
author lost@l-w.ca
date Wed, 07 Sep 2011 21:47:07 -0600
parents
children 3cd8aa013b88
comparison
equal deleted inserted replaced
174:411ef9735264 175:5e7f8e1ac99f
1 #!/usr/bin/perl
2 #
3 # these tests determine if the opcodes for each instruction, in each
4 # addressing mode, are correct.
5 #
6 # The following list is used to construct the tests. The key is the
7 # mneumonic and the value is a list of address mode characters as follows
8 #
9 # R: register/inherent
10 # I: immediate
11 # E: extended
12 # D: direct
13 # i: indexed
14 # r: register to register (TFR, etc.)
15 # p: psh/pul
16 # each letter is followed by an = and the 2 or 4 digit opcode in hex
17 # each entry is separated by a comma
18
19 $lwasm = './lwasm/lwasm';
20
21 %insnlist = (
22 'neg' => 'D=00,E=70,i=60',
23 'com' => 'D=03,E=73,i=63',
24 'lsr' => 'D=04,E=74,i=64',
25 'ror' => 'D=06,E=76,i=66',
26 'asr' => 'D=07,E=77,i=67',
27 'lsl' => 'D=08,E=78,i=68',
28 'rol' => 'D=09,E=79,i=69',
29 'dec' => 'D=0A,E=7A,i=6A',
30 'inc' => 'D=0C,E=7C,i=6C',
31 'tst' => 'D=0D,E=7D,i=6D',
32 'jmp' => 'D=0E,E=7E,i=6E',
33 'clr' => 'D=0F,E=7F,i=6F',
34 'nop' => 'R=12',
35 'sync' => 'R=13',
36 'lbra' => 'b=16',
37 'lbsr' => 'b=17',
38 'daa' => 'R=19',
39 'orcc' => 'I=1A',
40 'andcc' => 'I=1C',
41 'sex' => 'R=1D',
42 'exg' => 'r=1E',
43 'tfr' => 'r=1F',
44 'bra' => 'b=20',
45 'brn' => 'b=21',
46 'lbrn' => 'b=1021',
47 'bhi' => 'b=22',
48 'lbhi' => 'b=1022',
49 'bls' => 'b=23',
50 'lbls' => 'b=1023',
51 'bcc' => 'b=24',
52 'lbcc' => 'b=1024',
53 'bhs' => 'b=24',
54 'lbhs' => 'b=1024',
55 'bcs' => 'b=25',
56 'lbcs' => 'b=1025',
57 'blo' => 'b=25',
58 'lblo' => 'b=1025',
59 'bne' => 'b=26',
60 'lbne' => 'b=1026',
61 'beq' => 'b=27',
62 'lbeq' => 'b=1027',
63 'bvc' => 'b=28',
64 'lbvc' => 'b=1028',
65 'bvs' => 'b=29',
66 'lbvs' => 'b=1029',
67 'bpl' => 'b=2A',
68 'lbpl' => 'b=102A',
69 'bmi' => 'b=2B',
70 'lbmi' => 'b=102B',
71 'bge' => 'b=2C',
72 'lbge' => 'b=102C',
73 'blt' => 'b=2D',
74 'lblt' => 'b=102D',
75 'bgt' => 'b=2E',
76 'lbgt' => 'b=102E',
77 'ble' => 'b=2F',
78 'lble' => 'b=102F',
79 'leax' => 'i=30',
80 'leay' => 'i=31',
81 'leas' => 'i=32',
82 'leau' => 'i=33',
83 'pshs' => 'p=34',
84 'puls' => 'p=35',
85 'pshu' => 'p=36',
86 'pulu' => 'p=37',
87 'rts' => 'R=39',
88 'abx' => 'R=3A',
89 'rti' => 'R=3B',
90 'cwai' => 'I=3C',
91 'mul' => 'R=3D',
92 'swi' => 'R=3F',
93 'swi2' => 'R=103F',
94 'swi3' => 'R=113F',
95 'nega' => 'R=40',
96 'coma' => 'R=43',
97 'lsra' => 'R=44',
98 'rora' => 'R=46',
99 'asra' => 'R=47',
100 'lsla' => 'R=48',
101 'rola' => 'R=49',
102 'deca' => 'R=4A',
103 'inca' => 'R=4C',
104 'tsta' => 'R=4D',
105 'clra' => 'R=4F',
106 'negb' => 'R=50',
107 'comb' => 'R=53',
108 'lsrb' => 'R=54',
109 'rorb' => 'R=56',
110 'asrb' => 'R=57',
111 'lslb' => 'R=58',
112 'rolb' => 'R=59',
113 'decb' => 'R=5A',
114 'incb' => 'R=5C',
115 'tstb' => 'R=5D',
116 'clrb' => 'R=5F',
117 'suba' => 'I=80,D=90,i=A0,E=B0',
118 'cmpa' => 'I=81,D=91,i=A1,E=B1',
119 'sbca' => 'I=82,D=92,i=A2,E=B2',
120 'subd' => 'I=83,D=93,i=A3,E=B3',
121 'cmpd' => 'I=1083,D=1093,i=10A3,E=10B3',
122 'cmpu' => 'I=1183,D=1193,i=11A3,E=11B3',
123 'anda' => 'I=84,D=94,i=A4,E=B4',
124 'bita' => 'I=85,D=95,i=A5,E=B5',
125 'lda' => 'I=86,D=96,i=A6,E=B6',
126 'sta' => 'D=97,i=A7,E=B7',
127 'eora' => 'I=88,D=98,i=A8,E=B8',
128 'adca' => 'I=89,D=99,i=A9,E=B9',
129 'ora' => 'I=8A,D=9A,i=AA,E=BA',
130 'adda' => 'I=8B,D=9B,i=AB,E=BB',
131 'cmpx' => 'I=8C,D=9C,i=AC,E=BC',
132 'cmpy' => 'I=108C,D=109C,i=10AC,E=10BC',
133 'cmps' => 'I=118C,D=119C,i=11AC,E=11BC',
134 'bsr' => 'b=8D',
135 'jsr' => 'D=9D,i=AD,E=BD',
136 'ldx' => 'I=8E,D=9E,i=AE,E=BE',
137 'ldy' => 'I=108E,D=109E,i=10AE,E=10BE',
138 'stx' => 'D=9F,i=AF,E=BF',
139 'sty' => 'D=109F,i=10AF,E=10BF',
140 'subb' => 'I=C0,D=D0,i=E0,E=F0',
141 'cmpb' => 'I=C1,D=D1,i=E1,E=F1',
142 'sbcb' => 'I=C2,D=D2,i=E2,E=F2',
143 'addd' => 'I=C3,D=D3,i=E3,E=F3',
144 'andb' => 'I=C4,D=D4,i=E4,E=F4',
145 'bitb' => 'I=C5,D=D5,i=E5,E=F5',
146 'ldb' => 'I=C6,D=D6,i=E6,E=F6',
147 'stb' => 'D=D7,i=E7,E=F7',
148 'eorb' => 'I=C8,D=D8,i=E8,E=F8',
149 'adcb' => 'I=C9,D=D9,i=E9,E=F9',
150 'orb' => 'I=CA,D=DA,i=EA,E=FA',
151 'addb' => 'I=CB,D=DB,i=EB,E=FB',
152 'ldd' => 'I=CC,D=DC,i=EC,E=FC',
153 'std' => 'D=DD,i=ED,E=FD',
154 'ldu' => 'I=CE,D=DE,i=EE,E=FE',
155 'lds' => 'I=10CE,D=10DE,i=10EE,E=10FE',
156 'stu' => 'D=DF,i=EF,E=FF',
157 'sts' => 'D=10DF,i=10EF,E=10FF'
158
159 );
160
161 foreach $i (keys %insnlist)
162 {
163 # print "$i ... $insnlist{$i}\n";
164 @modes = split(/,/, $insnlist{$i});
165 foreach $j (@modes)
166 {
167 ($mc, $oc) = split(/=/, $j);
168 $operand = '';
169 if ($mc eq 'D')
170 {
171 $operand = '<0';
172 }
173 elsif ($mc eq 'E')
174 {
175 $operand = '>0';
176 }
177 elsif ($mc eq 'I')
178 {
179 $operand = '#0';
180 }
181 elsif ($mc eq 'i')
182 {
183 $operand = ',x';
184 }
185 elsif ($mc eq 'r')
186 {
187 $operand = 'a,a';
188 }
189 elsif ($mc eq 'p')
190 {
191 $operand = 'cc';
192 }
193 elsif ($mc eq 'b')
194 {
195 $operand = '*';
196 }
197 $asmcode = "\t$i $operand";
198
199 # now feed the asm code to the assembler and fetch the result
200 $tf = ".asmtmp.$$.$i.$mc";
201 open H, ">$tf.asm";
202 print H "$asmcode\n";
203 close H;
204 $r = `$lwasm --raw --list -o $tf $tf.asm`;
205 open H, "<$tf";
206 binmode H;
207 $buffer = '';
208 $r = read(H, $buffer, 10);
209 close H;
210 unlink $tf;
211 unlink "$tf.asm";
212 if ($r == 0)
213 {
214 $st = 'FAIL (no result)';
215 }
216 else
217 {
218 @bytes = split(//,$buffer);
219 $rc = sprintf('%02X', ord($bytes[0]));
220 if (length($oc) > 2)
221 {
222 $rc .= sprintf('%02X', ord($bytes[1]));
223 }
224 if ($rc ne $oc)
225 {
226 $st = "FAIL ($rc ≠ $oc, $asmcode)";
227 }
228 else
229 {
230 $st = 'PASS';
231 }
232 }
233 print "$i" . "_$mc $st\n";
234 }
235 }