]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/assembly/freescale/opcode.ma
Preparing for 0.5.9 release.
[helm.git] / helm / software / matita / contribs / assembly / freescale / opcode.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                           Progetto FreeScale                           *)
17 (*                                                                        *)
18 (* Sviluppato da:                                                         *)
19 (*   Cosimo Oliboni, oliboni@cs.unibo.it                                  *)
20 (*                                                                        *)
21 (* Questo materiale fa parte della tesi:                                  *)
22 (*   "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale"   *)
23 (*                                                                        *)
24 (*                    data ultima modifica 15/11/2007                     *)
25 (* ********************************************************************** *)
26
27 include "freescale/aux_bases.ma".
28
29 (* ********************************************** *)
30 (* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
31 (* ********************************************** *)
32
33 (* enumerazione delle ALU *)
34 inductive mcu_type: Type ≝
35   HC05  : mcu_type
36 | HC08  : mcu_type
37 | HCS08 : mcu_type
38 | RS08  : mcu_type.
39
40 (* enumerazione delle modalita' di indirizzamento = caricamento degli operandi *)
41 inductive instr_mode: Type ≝
42   (* INHERENT = nessun operando *)
43   MODE_INH  : instr_mode
44   (* INHERENT = nessun operando (A implicito) *)
45 | MODE_INHA : instr_mode
46   (* INHERENT = nessun operando (X implicito) *)
47 | MODE_INHX : instr_mode
48   (* INHERENT = nessun operando (H implicito) *)
49 | MODE_INHH : instr_mode
50
51   (* INHERENT_ADDRESS = nessun operando (HX implicito) *)
52 | MODE_INHX0ADD : instr_mode
53   (* INHERENT_ADDRESS = nessun operando (HX implicito+0x00bb) *)
54 | MODE_INHX1ADD : instr_mode
55   (* INHERENT_ADDRESS = nessun operando (HX implicito+0xwwww) *)
56 | MODE_INHX2ADD : instr_mode
57
58   (* IMMEDIATE = operando valore immediato byte = 0xbb *)
59 | MODE_IMM1 : instr_mode
60   (* IMMEDIATE_EXT = operando valore immediato byte = 0xbb -> esteso a word *)
61 | MODE_IMM1EXT : instr_mode
62   (* IMMEDIATE = operando valore immediato word = 0xwwww *)
63 | MODE_IMM2 : instr_mode
64   (* DIRECT = operando offset byte = [0x00bb] *)
65 | MODE_DIR1 : instr_mode
66   (* DIRECT = operando offset word = [0xwwww] *)
67 | MODE_DIR2 : instr_mode
68   (* INDEXED = nessun operando (implicito [X] *)
69 | MODE_IX0  : instr_mode
70   (* INDEXED = operando offset relativo byte = [X+0x00bb] *)
71 | MODE_IX1  : instr_mode
72   (* INDEXED = operando offset relativo word = [X+0xwwww] *)
73 | MODE_IX2  : instr_mode
74   (* INDEXED = operando offset relativo byte = [SP+0x00bb] *)
75 | MODE_SP1  : instr_mode
76   (* INDEXED = operando offset relativo word = [SP+0xwwww] *)
77 | MODE_SP2  : instr_mode
78
79   (* DIRECT → DIRECT = carica da diretto/scrive su diretto *)
80 | MODE_DIR1_to_DIR1 : instr_mode
81   (* IMMEDIATE → DIRECT = carica da immediato/scrive su diretto *)
82 | MODE_IMM1_to_DIR1 : instr_mode
83   (* INDEXED++ → DIRECT = carica da [X]/scrive su diretto/H:X++ *)
84 | MODE_IX0p_to_DIR1 : instr_mode
85   (* DIRECT → INDEXED++ = carica da diretto/scrive su [X]/H:X++ *)
86 | MODE_DIR1_to_IX0p : instr_mode
87
88   (* INHERENT(A) + IMMEDIATE *)
89 | MODE_INHA_and_IMM1 : instr_mode
90   (* INHERENT(X) + IMMEDIATE *)
91 | MODE_INHX_and_IMM1 : instr_mode
92   (* IMMEDIATE + IMMEDIATE *)
93 | MODE_IMM1_and_IMM1 : instr_mode
94   (* DIRECT + IMMEDIATE *)
95 | MODE_DIR1_and_IMM1 : instr_mode
96   (* INDEXED + IMMEDIATE *)
97 | MODE_IX0_and_IMM1  : instr_mode
98   (* INDEXED++ + IMMEDIATE *)
99 | MODE_IX0p_and_IMM1 : instr_mode
100   (* INDEXED + IMMEDIATE *)
101 | MODE_IX1_and_IMM1  : instr_mode
102   (* INDEXED++ + IMMEDIATE *)
103 | MODE_IX1p_and_IMM1 : instr_mode
104   (* INDEXED + IMMEDIATE *)
105 | MODE_SP1_and_IMM1  : instr_mode
106
107   (* DIRECT(mTNY) = operando offset byte(maschera scrittura implicita 3 bit) *)
108   (* ex: DIR3 e' carica b, scrivi b con n-simo bit modificato *)
109 | MODE_DIRn          : oct → instr_mode
110   (* DIRECT(mTNY) + IMMEDIATE = operando offset byte(maschera lettura implicita 3 bit) *)
111   (*                            + operando valore immediato byte  *)
112   (* ex: DIR2_and_IMM1 e' carica b, carica imm, restituisci n-simo bit di b + imm *)
113 | MODE_DIRn_and_IMM1 : oct → instr_mode
114   (* TINY = nessun operando (diretto implicito 4bit = [0x00000000:0000iiii]) *)
115 | MODE_TNY           : exadecim → instr_mode
116   (* SHORT = nessun operando (diretto implicito 5bit = [0x00000000:000iiiii]) *)
117 | MODE_SRT           : bitrigesim → instr_mode
118 .
119
120 (* enumerazione delle istruzioni di tutte le ALU *)
121 inductive opcode: Type ≝
122   ADC    : opcode (* add with carry *)
123 | ADD    : opcode (* add *)
124 | AIS    : opcode (* add immediate to SP *)
125 | AIX    : opcode (* add immediate to X *)
126 | AND    : opcode (* and *)
127 | ASL    : opcode (* aritmetic shift left *)
128 | ASR    : opcode (* aritmetic shift right *)
129 | BCC    : opcode (* branch if C=0 *)
130 | BCLRn  : opcode (* clear bit n *)
131 | BCS    : opcode (* branch if C=1 *)
132 | BEQ    : opcode (* branch if Z=1 *)
133 | BGE    : opcode (* branch if N⊙V=0 (great or equal) *)
134 | BGND   : opcode (* !!background mode!! *)
135 | BGT    : opcode (* branch if Z|N⊙V=0 clear (great) *)
136 | BHCC   : opcode (* branch if H=0 *)
137 | BHCS   : opcode (* branch if H=1 *)
138 | BHI    : opcode (* branch if C|Z=0, (higher) *)
139 | BIH    : opcode (* branch if nIRQ=1 *)
140 | BIL    : opcode (* branch if nIRQ=0 *)
141 | BIT    : opcode (* flag = and (bit test) *)
142 | BLE    : opcode (* branch if Z|N⊙V=1 (less or equal) *)
143 | BLS    : opcode (* branch if C|Z=1 (lower or same) *)
144 | BLT    : opcode (* branch if N⊙1=1 (less) *)
145 | BMC    : opcode (* branch if I=0 (interrupt mask clear) *)
146 | BMI    : opcode (* branch if N=1 (minus) *)
147 | BMS    : opcode (* branch if I=1 (interrupt mask set) *)
148 | BNE    : opcode (* branch if Z=0 *)
149 | BPL    : opcode (* branch if N=0 (plus) *)
150 | BRA    : opcode (* branch always *)
151 | BRCLRn : opcode (* branch if bit n clear *)
152 | BRN    : opcode (* branch never (nop) *)
153 | BRSETn : opcode (* branch if bit n set *)
154 | BSETn  : opcode (* set bit n *)
155 | BSR    : opcode (* branch to subroutine *)
156 | CBEQA  : opcode (* compare (A) and BEQ *)
157 | CBEQX  : opcode (* compare (X) and BEQ *)
158 | CLC    : opcode (* C=0 *)
159 | CLI    : opcode (* I=0 *)
160 | CLR    : opcode (* operand=0 *)
161 | CMP    : opcode (* flag = sub (compare A) *)
162 | COM    : opcode (* not (1 complement) *)
163 | CPHX   : opcode (* flag = sub (compare H:X) *)
164 | CPX    : opcode (* flag = sub (compare X) *)
165 | DAA    : opcode (* decimal adjust A *)
166 | DBNZ   : opcode (* dec and BNE *)
167 | DEC    : opcode (* operand=operand-1 (decrement) *)
168 | DIV    : opcode (* div *)
169 | EOR    : opcode (* xor *)
170 | INC    : opcode (* operand=operand+1 (increment) *)
171 | JMP    : opcode (* jmp word [operand] *)
172 | JSR    : opcode (* jmp to subroutine *)
173 | LDA    : opcode (* load in A *)
174 | LDHX   : opcode (* load in H:X *)
175 | LDX    : opcode (* load in X *)
176 | LSR    : opcode (* logical shift right *)
177 | MOV    : opcode (* move *)
178 | MUL    : opcode (* mul *)
179 | NEG    : opcode (* neg (2 complement) *)
180 | NOP    : opcode (* nop *)
181 | NSA    : opcode (* nibble swap A (al:ah <- ah:al) *)
182 | ORA    : opcode (* or *)
183 | PSHA   : opcode (* push A *)
184 | PSHH   : opcode (* push H *)
185 | PSHX   : opcode (* push X *)
186 | PULA   : opcode (* pop A *)
187 | PULH   : opcode (* pop H *)
188 | PULX   : opcode (* pop X *)
189 | ROL    : opcode (* rotate left *)
190 | ROR    : opcode (* rotate right *)
191 | RSP    : opcode (* reset SP (0x00FF) *)
192 | RTI    : opcode (* return from interrupt *)
193 | RTS    : opcode (* return from subroutine *)
194 | SBC    : opcode (* sub with carry*)
195 | SEC    : opcode (* C=1 *)
196 | SEI    : opcode (* I=1 *)
197 | SHA    : opcode (* swap spc_high,A *)
198 | SLA    : opcode (* swap spc_low,A *)
199 | STA    : opcode (* store from A *)
200 | STHX   : opcode (* store from H:X *)
201 | STOP   : opcode (* !!stop mode!! *)
202 | STX    : opcode (* store from X *)
203 | SUB    : opcode (* sub *)
204 | SWI    : opcode (* software interrupt *)
205 | TAP    : opcode (* flag=A (transfer A to process status byte *)
206 | TAX    : opcode (* X=A (transfer A to X) *)
207 | TPA    : opcode (* A=flag (transfer process status byte to A) *)
208 | TST    : opcode (* flag = sub (test) *)
209 | TSX    : opcode (* X:H=SP (transfer SP to H:X) *)
210 | TXA    : opcode (* A=X (transfer X to A) *)
211 | TXS    : opcode (* SP=X:H (transfer H:X to SP) *)
212 | WAIT   : opcode (* !!wait mode!! *)
213 .
214
215 (* introduzione di un tipo opcode dipendente dall'mcu_type (phantom type) *)
216 inductive any_opcode (m:mcu_type) : Type ≝
217  anyOP : opcode → any_opcode m.
218
219 definition c_anyOP ≝ anyOP.
220
221 coercion c_anyOP.
222
223 (* raggruppamento di byte e word in un tipo unico *)
224 inductive byte8_or_word16 : Type ≝
225   Byte: byte8  → byte8_or_word16
226 | Word: word16 → byte8_or_word16.
227
228 definition c_Byte ≝ Byte.
229 definition c_Word ≝ Word.
230
231 coercion c_Byte.
232 coercion c_Word.
233
234 (* opcode → naturali, per usare eqb *)
235 definition magic_of_opcode ≝
236 λo:opcode.match o with
237 [ ADC    ⇒ 〈x0,x0〉
238 | ADD    ⇒ 〈x0,x1〉
239 | AIS    ⇒ 〈x0,x2〉
240 | AIX    ⇒ 〈x0,x3〉
241 | AND    ⇒ 〈x0,x4〉
242 | ASL    ⇒ 〈x0,x5〉
243 | ASR    ⇒ 〈x0,x6〉
244 | BCC    ⇒ 〈x0,x7〉
245 | BCLRn  ⇒ 〈x0,x8〉
246 | BCS    ⇒ 〈x0,x9〉
247 | BEQ    ⇒ 〈x0,xA〉
248 | BGE    ⇒ 〈x0,xB〉
249 | BGND   ⇒ 〈x0,xC〉
250 | BGT    ⇒ 〈x0,xD〉
251 | BHCC   ⇒ 〈x0,xE〉
252 | BHCS   ⇒ 〈x0,xF〉
253 | BHI    ⇒ 〈x1,x0〉
254 | BIH    ⇒ 〈x1,x1〉
255 | BIL    ⇒ 〈x1,x2〉
256 | BIT    ⇒ 〈x1,x3〉
257 | BLE    ⇒ 〈x1,x4〉
258 | BLS    ⇒ 〈x1,x5〉
259 | BLT    ⇒ 〈x1,x6〉
260 | BMC    ⇒ 〈x1,x7〉
261 | BMI    ⇒ 〈x1,x8〉
262 | BMS    ⇒ 〈x1,x9〉
263 | BNE    ⇒ 〈x1,xA〉
264 | BPL    ⇒ 〈x1,xB〉
265 | BRA    ⇒ 〈x1,xC〉
266 | BRCLRn ⇒ 〈x1,xD〉
267 | BRN    ⇒ 〈x1,xE〉
268 | BRSETn ⇒ 〈x1,xF〉
269 | BSETn  ⇒ 〈x2,x0〉
270 | BSR    ⇒ 〈x2,x1〉
271 | CBEQA  ⇒ 〈x2,x2〉
272 | CBEQX  ⇒ 〈x2,x3〉
273 | CLC    ⇒ 〈x2,x4〉
274 | CLI    ⇒ 〈x2,x5〉
275 | CLR    ⇒ 〈x2,x6〉
276 | CMP    ⇒ 〈x2,x7〉
277 | COM    ⇒ 〈x2,x8〉
278 | CPHX   ⇒ 〈x2,x9〉
279 | CPX    ⇒ 〈x2,xA〉
280 | DAA    ⇒ 〈x2,xB〉
281 | DBNZ   ⇒ 〈x2,xC〉
282 | DEC    ⇒ 〈x2,xD〉
283 | DIV    ⇒ 〈x2,xE〉
284 | EOR    ⇒ 〈x2,xF〉
285 | INC    ⇒ 〈x3,x0〉
286 | JMP    ⇒ 〈x3,x1〉
287 | JSR    ⇒ 〈x3,x2〉
288 | LDA    ⇒ 〈x3,x3〉
289 | LDHX   ⇒ 〈x3,x4〉
290 | LDX    ⇒ 〈x3,x5〉
291 | LSR    ⇒ 〈x3,x6〉
292 | MOV    ⇒ 〈x3,x7〉
293 | MUL    ⇒ 〈x3,x8〉
294 | NEG    ⇒ 〈x3,x9〉
295 | NOP    ⇒ 〈x3,xA〉
296 | NSA    ⇒ 〈x3,xB〉
297 | ORA    ⇒ 〈x3,xC〉
298 | PSHA   ⇒ 〈x3,xD〉
299 | PSHH   ⇒ 〈x3,xE〉
300 | PSHX   ⇒ 〈x3,xF〉
301 | PULA   ⇒ 〈x4,x0〉
302 | PULH   ⇒ 〈x4,x1〉
303 | PULX   ⇒ 〈x4,x2〉
304 | ROL    ⇒ 〈x4,x3〉
305 | ROR    ⇒ 〈x4,x4〉
306 | RSP    ⇒ 〈x4,x5〉
307 | RTI    ⇒ 〈x4,x6〉
308 | RTS    ⇒ 〈x4,x7〉
309 | SBC    ⇒ 〈x4,x8〉
310 | SEC    ⇒ 〈x4,x9〉
311 | SEI    ⇒ 〈x4,xA〉
312 | SHA    ⇒ 〈x4,xB〉
313 | SLA    ⇒ 〈x4,xC〉
314 | STA    ⇒ 〈x4,xD〉
315 | STHX   ⇒ 〈x4,xE〉
316 | STOP   ⇒ 〈x4,xF〉
317 | STX    ⇒ 〈x5,x0〉
318 | SUB    ⇒ 〈x5,x1〉
319 | SWI    ⇒ 〈x5,x2〉
320 | TAP    ⇒ 〈x5,x3〉
321 | TAX    ⇒ 〈x5,x4〉
322 | TPA    ⇒ 〈x5,x5〉
323 | TST    ⇒ 〈x5,x6〉
324 | TSX    ⇒ 〈x5,x7〉
325 | TXA    ⇒ 〈x5,x8〉
326 | TXS    ⇒ 〈x5,x9〉
327 | WAIT   ⇒ 〈x5,xA〉
328 ].
329
330 (* confronto fra opcode, legale solo se tipati sulla stessa mcu *)
331 definition eqop ≝
332 λm:mcu_type.λo:any_opcode m.λo':any_opcode m.match o with
333  [ anyOP p ⇒ match o' with
334   [ anyOP p' ⇒ (eq_b8 (magic_of_opcode p) (magic_of_opcode p')) ] ].
335
336 (* instr_mode → naturali, per usare eqb *)
337 definition magic_of_instr_mode ≝
338 λi:instr_mode.match i with
339 [ MODE_INH  ⇒ 〈x0,x0〉
340 | MODE_INHA ⇒ 〈x0,x1〉
341 | MODE_INHX ⇒ 〈x0,x2〉
342 | MODE_INHH ⇒ 〈x0,x3〉
343
344 | MODE_INHX0ADD ⇒ 〈x0,x4〉
345 | MODE_INHX1ADD ⇒ 〈x0,x5〉
346 | MODE_INHX2ADD ⇒ 〈x0,x6〉
347
348 | MODE_IMM1 ⇒ 〈x0,x7〉
349 | MODE_IMM1EXT ⇒ 〈x0,x8〉
350 | MODE_IMM2 ⇒ 〈x0,x9〉
351 | MODE_DIR1 ⇒ 〈x0,xA〉
352 | MODE_DIR2 ⇒ 〈x0,xB〉
353 | MODE_IX0  ⇒ 〈x0,xC〉
354 | MODE_IX1  ⇒ 〈x0,xD〉
355 | MODE_IX2  ⇒ 〈x0,xE〉
356 | MODE_SP1  ⇒ 〈x0,xF〉
357 | MODE_SP2  ⇒ 〈x1,x0〉
358
359 | MODE_DIR1_to_DIR1 ⇒ 〈x1,x1〉
360 | MODE_IMM1_to_DIR1 ⇒ 〈x1,x2〉
361 | MODE_IX0p_to_DIR1 ⇒ 〈x1,x3〉
362 | MODE_DIR1_to_IX0p ⇒ 〈x1,x4〉
363
364 | MODE_INHA_and_IMM1 ⇒ 〈x1,x5〉
365 | MODE_INHX_and_IMM1 ⇒ 〈x1,x6〉
366 | MODE_IMM1_and_IMM1 ⇒ 〈x1,x7〉
367 | MODE_DIR1_and_IMM1 ⇒ 〈x1,x8〉
368 | MODE_IX0_and_IMM1  ⇒ 〈x1,x9〉
369 | MODE_IX0p_and_IMM1 ⇒ 〈x1,xA〉
370 | MODE_IX1_and_IMM1  ⇒ 〈x1,xB〉
371 | MODE_IX1p_and_IMM1 ⇒ 〈x1,xC〉
372 | MODE_SP1_and_IMM1  ⇒ 〈x1,xD〉
373
374   (* 27-34: bisogna considerare l'operando implicito *)
375 | MODE_DIRn o          ⇒ plus_b8nc 〈x1,xE〉 〈x0,(exadecim_of_oct o)〉
376   (* 35-42: bisogna considerare l'operando implicito *)
377 | MODE_DIRn_and_IMM1 o ⇒ plus_b8nc 〈x2,x6〉 〈x0,(exadecim_of_oct o)〉
378   (* 43-58: bisogna considerare l'operando implicito *)
379 | MODE_TNY e           ⇒ plus_b8nc 〈x2,xE〉 〈x0,e〉
380   (* 59-100: bisogna considerare gli operandi impliciti *)
381 | MODE_SRT t           ⇒ plus_b8nc 〈x3,xE〉 (byte8_of_bitrigesim t)
382 ].
383
384 (* confronto fra instr_mode *)
385 definition eqim ≝
386 λi:instr_mode.λi':instr_mode.(eq_b8 (magic_of_instr_mode i) (magic_of_instr_mode i')).
387
388 (* ********************************************* *)
389 (* STRUMENTI PER LE DIMOSTRAZIONI DI CORRETTEZZA *)
390 (* ********************************************* *)
391
392 (* su tutta la lista quante volte compare il byte *)
393 let rec get_byte_count (m:mcu_type) (b:byte8) (c:nat)
394  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
395  match l with
396   [ nil ⇒ c
397   | cons hd tl ⇒ match thd4T ???? hd with
398    [ Byte b' ⇒ match eq_b8 b b' with
399     [ true ⇒ get_byte_count m b (S c) tl
400     | false ⇒ get_byte_count m b c tl
401     ]
402    | Word _ ⇒ get_byte_count m b c tl
403    ]
404   ].
405
406 (* su tutta la lista quante volte compare la word (0x9E+byte) *)
407 let rec get_word_count (m:mcu_type) (b:byte8) (c:nat)
408  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
409  match l with
410   [ nil ⇒ c
411   | cons hd tl ⇒ match thd4T ???? hd with
412    [ Byte _ ⇒ get_word_count m b c tl
413    | Word w ⇒ match eq_w16 〈〈x9,xE〉:b〉 w with
414     [ true ⇒ get_word_count m b (S c) tl
415     | false ⇒ get_word_count m b c tl
416     ]
417    ]
418   ].
419
420 (* su tutta la lista quante volte compare lo pseudocodice *)
421 let rec get_pseudo_count (m:mcu_type) (o:opcode) (c:nat)
422  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
423  match l with
424   [ nil ⇒ c
425   | cons hd tl ⇒ match fst4T ???? hd with
426    [ anyOP o' ⇒ match eqop m (anyOP m o) (anyOP m o') with
427     [ true ⇒ get_pseudo_count m o (S c) tl
428     | false ⇒ get_pseudo_count m o c tl
429     ]
430    ]
431   ].
432
433 (* su tutta la lista quante volte compare la modalita' *)
434 let rec get_mode_count (m:mcu_type) (i:instr_mode) (c:nat)
435  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
436  match l with
437   [ nil ⇒ c
438   | cons hd tl ⇒ match eqim (snd4T ???? hd) i with
439    [ true ⇒ get_mode_count m i (S c) tl
440    | false ⇒ get_mode_count m i c tl
441    ]
442   ].
443
444 (* b e' non implementato? *)
445 let rec test_not_impl_byte (b:byte8) (l:list byte8) on l ≝
446  match l with
447   [ nil ⇒ false
448   | cons hd tl ⇒ match eq_b8 b hd with
449    [ true ⇒ true
450    | false ⇒ test_not_impl_byte b tl
451    ]
452   ].
453
454 (* o e' non implementato? *)
455 let rec test_not_impl_pseudo (o:opcode) (l:list opcode) on l ≝
456  match l with
457   [ nil ⇒ false
458   | cons hd tl ⇒ match eqop HC05 (anyOP HC05 o) (anyOP HC05 hd) with
459    [ true ⇒ true
460    | false ⇒ test_not_impl_pseudo o tl
461    ]
462   ].
463
464 (* i e' non implementato? *)
465 let rec test_not_impl_mode (i:instr_mode) (l:list instr_mode) on l ≝
466  match l with
467   [ nil ⇒ false
468   | cons hd tl ⇒ match eqim i hd with
469    [ true ⇒ true
470    | false ⇒ test_not_impl_mode i tl
471    ]
472   ].
473
474 (* su tutta la lista quante volte compare la coppia opcode,instr_mode *)
475 let rec get_OpIm_count (m:mcu_type) (o:any_opcode m) (i:instr_mode) (c:nat)
476  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
477  match l with
478   [ nil ⇒ c
479   | cons hd tl ⇒
480    match (eqop m o (fst4T ???? hd)) ⊗
481          (eqim i (snd4T ???? hd)) with
482     [ true ⇒ get_OpIm_count m o i (S c) tl
483     | false ⇒ get_OpIm_count m o i c tl
484     ] 
485   ].
486
487 (* iteratore sugli opcode *)
488 definition forall_opcode ≝ λP.
489  P ADC    ⊗ P ADD    ⊗ P AIS    ⊗ P AIX    ⊗ P AND    ⊗ P ASL    ⊗ P ASR    ⊗ P BCC    ⊗
490  P BCLRn  ⊗ P BCS    ⊗ P BEQ    ⊗ P BGE    ⊗ P BGND   ⊗ P BGT    ⊗ P BHCC   ⊗ P BHCS   ⊗
491  P BHI    ⊗ P BIH    ⊗ P BIL    ⊗ P BIT    ⊗ P BLE    ⊗ P BLS    ⊗ P BLT    ⊗ P BMC    ⊗
492  P BMI    ⊗ P BMS    ⊗ P BNE    ⊗ P BPL    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRN    ⊗ P BRSETn ⊗
493  P BSETn  ⊗ P BSR    ⊗ P CBEQA  ⊗ P CBEQX  ⊗ P CLC    ⊗ P CLI    ⊗ P CLR    ⊗ P CMP    ⊗
494  P COM    ⊗ P CPHX   ⊗ P CPX    ⊗ P DAA    ⊗ P DBNZ   ⊗ P DEC    ⊗ P DIV    ⊗ P EOR    ⊗
495  P INC    ⊗ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LDHX   ⊗ P LDX    ⊗ P LSR    ⊗ P MOV    ⊗
496  P MUL    ⊗ P NEG    ⊗ P NOP    ⊗ P NSA    ⊗ P ORA    ⊗ P PSHA   ⊗ P PSHH   ⊗ P PSHX   ⊗
497  P PULA   ⊗ P PULH   ⊗ P PULX   ⊗ P ROL    ⊗ P ROR    ⊗ P RSP    ⊗ P RTI    ⊗ P RTS    ⊗
498  P SBC    ⊗ P SEC    ⊗ P SEI    ⊗ P SHA    ⊗ P SLA    ⊗ P STA    ⊗ P STHX   ⊗ P STOP   ⊗
499  P STX    ⊗ P SUB    ⊗ P SWI    ⊗ P TAP    ⊗ P TAX    ⊗ P TPA    ⊗ P TST    ⊗ P TSX    ⊗
500  P TXA    ⊗ P TXS    ⊗ P WAIT.
501
502 (* iteratore sulle modalita' *)
503 definition forall_instr_mode ≝ λP.
504   P MODE_INH
505 ⊗ P MODE_INHA
506 ⊗ P MODE_INHX
507 ⊗ P MODE_INHH
508
509 ⊗ P MODE_INHX0ADD
510 ⊗ P MODE_INHX1ADD
511 ⊗ P MODE_INHX2ADD
512
513 ⊗ P MODE_IMM1
514 ⊗ P MODE_IMM1EXT
515 ⊗ P MODE_IMM2
516 ⊗ P MODE_DIR1
517 ⊗ P MODE_DIR2
518 ⊗ P MODE_IX0
519 ⊗ P MODE_IX1
520 ⊗ P MODE_IX2
521 ⊗ P MODE_SP1
522 ⊗ P MODE_SP2
523
524 ⊗ P MODE_DIR1_to_DIR1
525 ⊗ P MODE_IMM1_to_DIR1
526 ⊗ P MODE_IX0p_to_DIR1
527 ⊗ P MODE_DIR1_to_IX0p
528
529 ⊗ P MODE_INHA_and_IMM1
530 ⊗ P MODE_INHX_and_IMM1
531 ⊗ P MODE_IMM1_and_IMM1
532 ⊗ P MODE_DIR1_and_IMM1
533 ⊗ P MODE_IX0_and_IMM1
534 ⊗ P MODE_IX0p_and_IMM1
535 ⊗ P MODE_IX1_and_IMM1
536 ⊗ P MODE_IX1p_and_IMM1
537 ⊗ P MODE_SP1_and_IMM1
538
539 ⊗ forall_oct (λo. P (MODE_DIRn o))
540 ⊗ forall_oct (λo. P (MODE_DIRn_and_IMM1 o))
541 ⊗ forall_exadecim (λe. P (MODE_TNY e))
542 ⊗ forall_bitrigesim (λt. P (MODE_SRT t)).