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