]> matita.cs.unibo.it Git - helm.git/blob - matita/contribs/assembly/freescale/opcode.ma
tagged 0.5.0-rc1
[helm.git] / 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 coercion cic:/matita/freescale/opcode/any_opcode.ind#xpointer(1/1/1).
220
221 (* raggruppamento di byte e word in un tipo unico *)
222 inductive byte8_or_word16 : Type ≝
223   Byte: byte8  → byte8_or_word16
224 | Word: word16 → byte8_or_word16.
225
226 coercion cic:/matita/freescale/opcode/byte8_or_word16.ind#xpointer(1/1/1).
227 coercion cic:/matita/freescale/opcode/byte8_or_word16.ind#xpointer(1/1/2).
228
229 (* opcode → naturali, per usare eqb *)
230 definition magic_of_opcode ≝
231 λo:opcode.match o with
232 [ ADC    ⇒ 〈x0,x0〉
233 | ADD    ⇒ 〈x0,x1〉
234 | AIS    ⇒ 〈x0,x2〉
235 | AIX    ⇒ 〈x0,x3〉
236 | AND    ⇒ 〈x0,x4〉
237 | ASL    ⇒ 〈x0,x5〉
238 | ASR    ⇒ 〈x0,x6〉
239 | BCC    ⇒ 〈x0,x7〉
240 | BCLRn  ⇒ 〈x0,x8〉
241 | BCS    ⇒ 〈x0,x9〉
242 | BEQ    ⇒ 〈x0,xA〉
243 | BGE    ⇒ 〈x0,xB〉
244 | BGND   ⇒ 〈x0,xC〉
245 | BGT    ⇒ 〈x0,xD〉
246 | BHCC   ⇒ 〈x0,xE〉
247 | BHCS   ⇒ 〈x0,xF〉
248 | BHI    ⇒ 〈x1,x0〉
249 | BIH    ⇒ 〈x1,x1〉
250 | BIL    ⇒ 〈x1,x2〉
251 | BIT    ⇒ 〈x1,x3〉
252 | BLE    ⇒ 〈x1,x4〉
253 | BLS    ⇒ 〈x1,x5〉
254 | BLT    ⇒ 〈x1,x6〉
255 | BMC    ⇒ 〈x1,x7〉
256 | BMI    ⇒ 〈x1,x8〉
257 | BMS    ⇒ 〈x1,x9〉
258 | BNE    ⇒ 〈x1,xA〉
259 | BPL    ⇒ 〈x1,xB〉
260 | BRA    ⇒ 〈x1,xC〉
261 | BRCLRn ⇒ 〈x1,xD〉
262 | BRN    ⇒ 〈x1,xE〉
263 | BRSETn ⇒ 〈x1,xF〉
264 | BSETn  ⇒ 〈x2,x0〉
265 | BSR    ⇒ 〈x2,x1〉
266 | CBEQA  ⇒ 〈x2,x2〉
267 | CBEQX  ⇒ 〈x2,x3〉
268 | CLC    ⇒ 〈x2,x4〉
269 | CLI    ⇒ 〈x2,x5〉
270 | CLR    ⇒ 〈x2,x6〉
271 | CMP    ⇒ 〈x2,x7〉
272 | COM    ⇒ 〈x2,x8〉
273 | CPHX   ⇒ 〈x2,x9〉
274 | CPX    ⇒ 〈x2,xA〉
275 | DAA    ⇒ 〈x2,xB〉
276 | DBNZ   ⇒ 〈x2,xC〉
277 | DEC    ⇒ 〈x2,xD〉
278 | DIV    ⇒ 〈x2,xE〉
279 | EOR    ⇒ 〈x2,xF〉
280 | INC    ⇒ 〈x3,x0〉
281 | JMP    ⇒ 〈x3,x1〉
282 | JSR    ⇒ 〈x3,x2〉
283 | LDA    ⇒ 〈x3,x3〉
284 | LDHX   ⇒ 〈x3,x4〉
285 | LDX    ⇒ 〈x3,x5〉
286 | LSR    ⇒ 〈x3,x6〉
287 | MOV    ⇒ 〈x3,x7〉
288 | MUL    ⇒ 〈x3,x8〉
289 | NEG    ⇒ 〈x3,x9〉
290 | NOP    ⇒ 〈x3,xA〉
291 | NSA    ⇒ 〈x3,xB〉
292 | ORA    ⇒ 〈x3,xC〉
293 | PSHA   ⇒ 〈x3,xD〉
294 | PSHH   ⇒ 〈x3,xE〉
295 | PSHX   ⇒ 〈x3,xF〉
296 | PULA   ⇒ 〈x4,x0〉
297 | PULH   ⇒ 〈x4,x1〉
298 | PULX   ⇒ 〈x4,x2〉
299 | ROL    ⇒ 〈x4,x3〉
300 | ROR    ⇒ 〈x4,x4〉
301 | RSP    ⇒ 〈x4,x5〉
302 | RTI    ⇒ 〈x4,x6〉
303 | RTS    ⇒ 〈x4,x7〉
304 | SBC    ⇒ 〈x4,x8〉
305 | SEC    ⇒ 〈x4,x9〉
306 | SEI    ⇒ 〈x4,xA〉
307 | SHA    ⇒ 〈x4,xB〉
308 | SLA    ⇒ 〈x4,xC〉
309 | STA    ⇒ 〈x4,xD〉
310 | STHX   ⇒ 〈x4,xE〉
311 | STOP   ⇒ 〈x4,xF〉
312 | STX    ⇒ 〈x5,x0〉
313 | SUB    ⇒ 〈x5,x1〉
314 | SWI    ⇒ 〈x5,x2〉
315 | TAP    ⇒ 〈x5,x3〉
316 | TAX    ⇒ 〈x5,x4〉
317 | TPA    ⇒ 〈x5,x5〉
318 | TST    ⇒ 〈x5,x6〉
319 | TSX    ⇒ 〈x5,x7〉
320 | TXA    ⇒ 〈x5,x8〉
321 | TXS    ⇒ 〈x5,x9〉
322 | WAIT   ⇒ 〈x5,xA〉
323 ].
324
325 (* confronto fra opcode, legale solo se tipati sulla stessa mcu *)
326 definition eqop ≝
327 λm:mcu_type.λo:any_opcode m.λo':any_opcode m.match o with
328  [ anyOP p ⇒ match o' with
329   [ anyOP p' ⇒ (eq_b8 (magic_of_opcode p) (magic_of_opcode p')) ] ].
330
331 (* instr_mode → naturali, per usare eqb *)
332 definition magic_of_instr_mode ≝
333 λi:instr_mode.match i with
334 [ MODE_INH  ⇒ 〈x0,x0〉
335 | MODE_INHA ⇒ 〈x0,x1〉
336 | MODE_INHX ⇒ 〈x0,x2〉
337 | MODE_INHH ⇒ 〈x0,x3〉
338
339 | MODE_INHX0ADD ⇒ 〈x0,x4〉
340 | MODE_INHX1ADD ⇒ 〈x0,x5〉
341 | MODE_INHX2ADD ⇒ 〈x0,x6〉
342
343 | MODE_IMM1 ⇒ 〈x0,x7〉
344 | MODE_IMM1EXT ⇒ 〈x0,x8〉
345 | MODE_IMM2 ⇒ 〈x0,x9〉
346 | MODE_DIR1 ⇒ 〈x0,xA〉
347 | MODE_DIR2 ⇒ 〈x0,xB〉
348 | MODE_IX0  ⇒ 〈x0,xC〉
349 | MODE_IX1  ⇒ 〈x0,xD〉
350 | MODE_IX2  ⇒ 〈x0,xE〉
351 | MODE_SP1  ⇒ 〈x0,xF〉
352 | MODE_SP2  ⇒ 〈x1,x0〉
353
354 | MODE_DIR1_to_DIR1 ⇒ 〈x1,x1〉
355 | MODE_IMM1_to_DIR1 ⇒ 〈x1,x2〉
356 | MODE_IX0p_to_DIR1 ⇒ 〈x1,x3〉
357 | MODE_DIR1_to_IX0p ⇒ 〈x1,x4〉
358
359 | MODE_INHA_and_IMM1 ⇒ 〈x1,x5〉
360 | MODE_INHX_and_IMM1 ⇒ 〈x1,x6〉
361 | MODE_IMM1_and_IMM1 ⇒ 〈x1,x7〉
362 | MODE_DIR1_and_IMM1 ⇒ 〈x1,x8〉
363 | MODE_IX0_and_IMM1  ⇒ 〈x1,x9〉
364 | MODE_IX0p_and_IMM1 ⇒ 〈x1,xA〉
365 | MODE_IX1_and_IMM1  ⇒ 〈x1,xB〉
366 | MODE_IX1p_and_IMM1 ⇒ 〈x1,xC〉
367 | MODE_SP1_and_IMM1  ⇒ 〈x1,xD〉
368
369   (* 27-34: bisogna considerare l'operando implicito *)
370 | MODE_DIRn o          ⇒ plus_b8nc 〈x1,xE〉 〈x0,(exadecim_of_oct o)〉
371   (* 35-42: bisogna considerare l'operando implicito *)
372 | MODE_DIRn_and_IMM1 o ⇒ plus_b8nc 〈x2,x6〉 〈x0,(exadecim_of_oct o)〉
373   (* 43-58: bisogna considerare l'operando implicito *)
374 | MODE_TNY e           ⇒ plus_b8nc 〈x2,xE〉 〈x0,e〉
375   (* 59-100: bisogna considerare gli operandi impliciti *)
376 | MODE_SRT t           ⇒ plus_b8nc 〈x3,xE〉 (byte8_of_bitrigesim t)
377 ].
378
379 (* confronto fra instr_mode *)
380 definition eqim ≝
381 λi:instr_mode.λi':instr_mode.(eq_b8 (magic_of_instr_mode i) (magic_of_instr_mode i')).
382
383 (* ********************************************* *)
384 (* STRUMENTI PER LE DIMOSTRAZIONI DI CORRETTEZZA *)
385 (* ********************************************* *)
386
387 (* su tutta la lista quante volte compare il byte *)
388 let rec get_byte_count (m:mcu_type) (b:byte8) (c:nat)
389  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
390  match l with
391   [ nil ⇒ c
392   | cons hd tl ⇒ match thd4T ???? hd with
393    [ Byte b' ⇒ match eq_b8 b b' with
394     [ true ⇒ get_byte_count m b (S c) tl
395     | false ⇒ get_byte_count m b c tl
396     ]
397    | Word _ ⇒ get_byte_count m b c tl
398    ]
399   ].
400
401 (* su tutta la lista quante volte compare la word (0x9E+byte) *)
402 let rec get_word_count (m:mcu_type) (b:byte8) (c:nat)
403  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
404  match l with
405   [ nil ⇒ c
406   | cons hd tl ⇒ match thd4T ???? hd with
407    [ Byte _ ⇒ get_word_count m b c tl
408    | Word w ⇒ match eq_w16 〈〈x9,xE〉:b〉 w with
409     [ true ⇒ get_word_count m b (S c) tl
410     | false ⇒ get_word_count m b c tl
411     ]
412    ]
413   ].
414
415 (* su tutta la lista quante volte compare lo pseudocodice *)
416 let rec get_pseudo_count (m:mcu_type) (o:opcode) (c:nat)
417  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
418  match l with
419   [ nil ⇒ c
420   | cons hd tl ⇒ match fst4T ???? hd with
421    [ anyOP o' ⇒ match eqop m (anyOP m o) (anyOP m o') with
422     [ true ⇒ get_pseudo_count m o (S c) tl
423     | false ⇒ get_pseudo_count m o c tl
424     ]
425    ]
426   ].
427
428 (* su tutta la lista quante volte compare la modalita' *)
429 let rec get_mode_count (m:mcu_type) (i:instr_mode) (c:nat)
430  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
431  match l with
432   [ nil ⇒ c
433   | cons hd tl ⇒ match eqim (snd4T ???? hd) i with
434    [ true ⇒ get_mode_count m i (S c) tl
435    | false ⇒ get_mode_count m i c tl
436    ]
437   ].
438
439 (* b e' non implementato? *)
440 let rec test_not_impl_byte (b:byte8) (l:list byte8) on l ≝
441  match l with
442   [ nil ⇒ false
443   | cons hd tl ⇒ match eq_b8 b hd with
444    [ true ⇒ true
445    | false ⇒ test_not_impl_byte b tl
446    ]
447   ].
448
449 (* o e' non implementato? *)
450 let rec test_not_impl_pseudo (o:opcode) (l:list opcode) on l ≝
451  match l with
452   [ nil ⇒ false
453   | cons hd tl ⇒ match eqop HC05 (anyOP HC05 o) (anyOP HC05 hd) with
454    [ true ⇒ true
455    | false ⇒ test_not_impl_pseudo o tl
456    ]
457   ].
458
459 (* i e' non implementato? *)
460 let rec test_not_impl_mode (i:instr_mode) (l:list instr_mode) on l ≝
461  match l with
462   [ nil ⇒ false
463   | cons hd tl ⇒ match eqim i hd with
464    [ true ⇒ true
465    | false ⇒ test_not_impl_mode i tl
466    ]
467   ].
468
469 (* su tutta la lista quante volte compare la coppia opcode,instr_mode *)
470 let rec get_OpIm_count (m:mcu_type) (o:any_opcode m) (i:instr_mode) (c:nat)
471  (l:list (Prod4T (any_opcode m) instr_mode byte8_or_word16 byte8)) on l ≝
472  match l with
473   [ nil ⇒ c
474   | cons hd tl ⇒
475    match (eqop m o (fst4T ???? hd)) ⊗
476          (eqim i (snd4T ???? hd)) with
477     [ true ⇒ get_OpIm_count m o i (S c) tl
478     | false ⇒ get_OpIm_count m o i c tl
479     ] 
480   ].
481
482 (* iteratore sugli opcode *)
483 definition forall_opcode ≝ λP.
484  P ADC    ⊗ P ADD    ⊗ P AIS    ⊗ P AIX    ⊗ P AND    ⊗ P ASL    ⊗ P ASR    ⊗ P BCC    ⊗
485  P BCLRn  ⊗ P BCS    ⊗ P BEQ    ⊗ P BGE    ⊗ P BGND   ⊗ P BGT    ⊗ P BHCC   ⊗ P BHCS   ⊗
486  P BHI    ⊗ P BIH    ⊗ P BIL    ⊗ P BIT    ⊗ P BLE    ⊗ P BLS    ⊗ P BLT    ⊗ P BMC    ⊗
487  P BMI    ⊗ P BMS    ⊗ P BNE    ⊗ P BPL    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRN    ⊗ P BRSETn ⊗
488  P BSETn  ⊗ P BSR    ⊗ P CBEQA  ⊗ P CBEQX  ⊗ P CLC    ⊗ P CLI    ⊗ P CLR    ⊗ P CMP    ⊗
489  P COM    ⊗ P CPHX   ⊗ P CPX    ⊗ P DAA    ⊗ P DBNZ   ⊗ P DEC    ⊗ P DIV    ⊗ P EOR    ⊗
490  P INC    ⊗ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LDHX   ⊗ P LDX    ⊗ P LSR    ⊗ P MOV    ⊗
491  P MUL    ⊗ P NEG    ⊗ P NOP    ⊗ P NSA    ⊗ P ORA    ⊗ P PSHA   ⊗ P PSHH   ⊗ P PSHX   ⊗
492  P PULA   ⊗ P PULH   ⊗ P PULX   ⊗ P ROL    ⊗ P ROR    ⊗ P RSP    ⊗ P RTI    ⊗ P RTS    ⊗
493  P SBC    ⊗ P SEC    ⊗ P SEI    ⊗ P SHA    ⊗ P SLA    ⊗ P STA    ⊗ P STHX   ⊗ P STOP   ⊗
494  P STX    ⊗ P SUB    ⊗ P SWI    ⊗ P TAP    ⊗ P TAX    ⊗ P TPA    ⊗ P TST    ⊗ P TSX    ⊗
495  P TXA    ⊗ P TXS    ⊗ P WAIT.
496
497 (* iteratore sulle modalita' *)
498 definition forall_instr_mode ≝ λP.
499   P MODE_INH
500 ⊗ P MODE_INHA
501 ⊗ P MODE_INHX
502 ⊗ P MODE_INHH
503
504 ⊗ P MODE_INHX0ADD
505 ⊗ P MODE_INHX1ADD
506 ⊗ P MODE_INHX2ADD
507
508 ⊗ P MODE_IMM1
509 ⊗ P MODE_IMM1EXT
510 ⊗ P MODE_IMM2
511 ⊗ P MODE_DIR1
512 ⊗ P MODE_DIR2
513 ⊗ P MODE_IX0
514 ⊗ P MODE_IX1
515 ⊗ P MODE_IX2
516 ⊗ P MODE_SP1
517 ⊗ P MODE_SP2
518
519 ⊗ P MODE_DIR1_to_DIR1
520 ⊗ P MODE_IMM1_to_DIR1
521 ⊗ P MODE_IX0p_to_DIR1
522 ⊗ P MODE_DIR1_to_IX0p
523
524 ⊗ P MODE_INHA_and_IMM1
525 ⊗ P MODE_INHX_and_IMM1
526 ⊗ P MODE_IMM1_and_IMM1
527 ⊗ P MODE_DIR1_and_IMM1
528 ⊗ P MODE_IX0_and_IMM1
529 ⊗ P MODE_IX0p_and_IMM1
530 ⊗ P MODE_IX1_and_IMM1
531 ⊗ P MODE_IX1p_and_IMM1
532 ⊗ P MODE_SP1_and_IMM1
533
534 ⊗ forall_oct (λo. P (MODE_DIRn o))
535 ⊗ forall_oct (λo. P (MODE_DIRn_and_IMM1 o))
536 ⊗ forall_exadecim (λe. P (MODE_TNY e))
537 ⊗ forall_bitrigesim (λt. P (MODE_SRT t)).