source: src/ASM/AssemblyProof.ma @ 1649

Last change on this file since 1649 was 1649, checked in by boender, 6 years ago
  • changes to Assembly for integration with Policy and easier use of _safe functions (with CSC)
File size: 88.5 KB
Line 
1include "ASM/Assembly.ma".
2include "ASM/Interpret.ma".
3include "ASM/StatusProofs.ma".
4include alias "arithmetics/nat.ma".
5
6definition bit_elim_prop: ∀P: bool → Prop. Prop ≝
7  λP.
8    P true ∧ P false.
9 
10let rec bitvector_elim_prop_internal
11  (n: nat) (P: BitVector n → Prop) (m: nat) on m: m ≤ n → BitVector (n - m) → Prop ≝
12  match m return λm. m ≤ n → BitVector (n - m) → Prop with
13  [ O    ⇒ λprf1. λprefix. P ?
14  | S n' ⇒ λprf2. λprefix. bit_elim_prop (λbit. bitvector_elim_prop_internal n P n' ? ?)
15  ].
16  [ applyS prefix
17  | letin res ≝ (bit ::: prefix)
18    < (minus_S_S ? ?)
19    > (minus_Sn_m ? ?)
20  [ @ res
21  | @ prf2
22  ]
23  | /2/
24  ].
25qed.
26
27definition bitvector_elim_prop ≝
28  λn: nat.
29  λP: BitVector n → Prop.
30    bitvector_elim_prop_internal n P n ? ?.
31  [ @ (le_n ?)
32  | < (minus_n_n ?)
33    @ [[ ]]
34  ]
35qed.
36
37lemma bool_eq_internal_eq:
38  ∀b, c.
39    (λb. λc. (if b then c else (if c then false else true))) b c = true → b = c.
40  #b #c
41  cases b
42  [ normalize //
43  | normalize
44    cases c
45    [ normalize //
46    | normalize //
47    ]
48  ]
49qed.
50
51definition bit_elim: ∀P: bool → bool. bool ≝
52  λP.
53    P true ∧ P false.
54
55let rec bitvector_elim_internal
56  (n: nat) (P: BitVector n → bool) (m: nat) on m: m ≤ n → BitVector (n - m) → bool ≝
57  match m return λm. m ≤ n → BitVector (n - m) → bool with
58  [ O    ⇒ λprf1. λprefix. P ?
59  | S n' ⇒ λprf2. λprefix. bit_elim (λbit. bitvector_elim_internal n P n' ? ?)
60  ].
61  [ applyS prefix
62  | letin res ≝ (bit ::: prefix)
63    < (minus_S_S ? ?)
64    > (minus_Sn_m ? ?)
65    [ @ res
66    | @ prf2
67    ]
68  | /2/
69  ].
70qed.
71
72definition bitvector_elim ≝
73  λn: nat.
74  λP: BitVector n → bool.
75    bitvector_elim_internal n P n ? ?.
76  [ @ (le_n ?)
77  | < (minus_n_n ?)
78    @ [[ ]]
79  ]
80qed.
81
82lemma super_rewrite2:
83 ∀A:Type[0].∀n,m.∀v1: Vector A n.∀v2: Vector A m.
84  ∀P: ∀m. Vector A m → Prop.
85   n=m → v1 ≃ v2 → P n v1 → P m v2.
86 #A #n #m #v1 #v2 #P #EQ <EQ in v2; #V #JMEQ >JMEQ //
87qed.
88
89lemma vector_cons_append:
90  ∀A: Type[0].
91  ∀n: nat.
92  ∀e: A.
93  ∀v: Vector A n.
94    e ::: v = [[ e ]] @@ v.
95  # A # N # E # V
96  elim V
97  [ normalize %
98  | # NN # AA # VV # IH
99    normalize
100    %
101qed.
102
103lemma vector_cons_append2:
104  ∀A: Type[0].
105  ∀n, m: nat.
106  ∀v: Vector A n.
107  ∀q: Vector A m.
108  ∀hd: A.
109    hd:::(v@@q) = (hd:::v)@@q.
110  #A #n #m #v #q
111  elim v
112  [ #hd %
113  | #n' #hd' #tl' #ih #hd' <ih %
114  ]
115qed.
116
117lemma jmeq_cons_vector_monotone:
118  ∀A: Type[0].
119  ∀m, n: nat.
120  ∀v: Vector A m.
121  ∀q: Vector A n.
122  ∀prf: m = n.
123  ∀hd: A.
124    v ≃ q → hd:::v ≃ hd:::q.
125  #A #m #n #v #q #prf #hd #E
126  @(super_rewrite2 A … E)
127  [ assumption | % ]
128qed.
129
130lemma vector_associative_append:
131  ∀A: Type[0].
132  ∀n, m, o:  nat.
133  ∀v: Vector A n.
134  ∀q: Vector A m.
135  ∀r: Vector A o.
136    ((v @@ q) @@ r)
137    ≃
138    (v @@ (q @@ r)).
139  #A #n #m #o #v #q #r
140  elim v
141  [ %
142  | #n' #hd #tl #ih
143    <(vector_cons_append2 A … hd)
144    @jmeq_cons_vector_monotone
145    //
146  ]
147qed.
148
149lemma mem_middle_vector:
150  ∀A: Type[0].
151  ∀m, o: nat.
152  ∀eq: A → A → bool.
153  ∀reflex: ∀a. eq a a = true.
154  ∀p: Vector A m.
155  ∀a: A.
156  ∀r: Vector A o.
157    mem A eq ? (p@@(a:::r)) a = true.
158  # A # M # O # EQ # REFLEX # P # A
159  elim P
160  [ normalize
161    > (REFLEX A)
162    normalize
163    # H
164    %
165  | # NN # AA # PP # IH
166    normalize
167    cases (EQ A AA) //
168     @ IH
169  ]
170qed.
171
172lemma mem_monotonic_wrt_append:
173  ∀A: Type[0].
174  ∀m, o: nat.
175  ∀eq: A → A → bool.
176  ∀reflex: ∀a. eq a a = true.
177  ∀p: Vector A m.
178  ∀a: A.
179  ∀r: Vector A o.
180    mem A eq ? r a = true → mem A eq ? (p @@ r) a = true.
181  # A # M # O # EQ # REFLEX # P # A
182  elim P
183  [ #R #H @H
184  | #NN #AA # PP # IH #R #H
185    normalize
186    cases (EQ A AA)
187    [ normalize %
188    | @ IH @ H
189    ]
190  ]
191qed.
192
193lemma subvector_multiple_append:
194  ∀A: Type[0].
195  ∀o, n: nat.
196  ∀eq: A → A → bool.
197  ∀refl: ∀a. eq a a = true.
198  ∀h: Vector A o.
199  ∀v: Vector A n.
200  ∀m: nat.
201  ∀q: Vector A m.
202    bool_to_Prop (subvector_with A ? ? eq v (h @@ q @@ v)).
203  # A # O # N # EQ # REFLEX # H # V
204  elim V
205  [ normalize
206    # M # V %
207  | # NN # AA # VV # IH # MM # QQ
208    change with (bool_to_Prop (andb ??))
209    cut ((mem A EQ (O + (MM + S NN)) (H@@QQ@@AA:::VV) AA) = true)
210    [
211    | # HH > HH
212      > (vector_cons_append ? ? AA VV)
213      change with (bool_to_Prop (subvector_with ??????))
214      @(super_rewrite2 A ((MM + 1)+ NN) (MM+S NN) ??
215        (λSS.λVS.bool_to_Prop (subvector_with ?? (O+SS) ?? (H@@VS)))
216        ?
217        (vector_associative_append A ? ? ? QQ [[AA]] VV))
218      [ >associative_plus //
219      | @IH ]
220    ]
221    @(mem_monotonic_wrt_append)
222    [ @ REFLEX
223    | @(mem_monotonic_wrt_append)
224      [ @ REFLEX
225      | normalize
226        > REFLEX
227        normalize
228        %
229      ]
230    ]
231qed.
232
233lemma vector_cons_empty:
234  ∀A: Type[0].
235  ∀n: nat.
236  ∀v: Vector A n.
237    [[ ]] @@ v = v.
238  # A # N # V
239  elim V
240  [ normalize %
241  | # NN # HH # VV #H %
242  ]
243qed.
244
245corollary subvector_hd_tl:
246  ∀A: Type[0].
247  ∀o: nat.
248  ∀eq: A → A → bool.
249  ∀refl: ∀a. eq a a = true.
250  ∀h: A.
251  ∀v: Vector A o.
252    bool_to_Prop (subvector_with A ? ? eq v (h ::: v)).
253  # A # O # EQ # REFLEX # H # V
254  > (vector_cons_append A ? H V)
255  < (vector_cons_empty A ? ([[H]] @@ V))
256  @ (subvector_multiple_append A ? ? EQ REFLEX [[]] V ? [[ H ]])
257qed.
258
259lemma eq_a_reflexive:
260  ∀a. eq_a a a = true.
261  # A
262  cases A
263  %
264qed.
265
266lemma is_in_monotonic_wrt_append:
267  ∀m, n: nat.
268  ∀p: Vector addressing_mode_tag m.
269  ∀q: Vector addressing_mode_tag n.
270  ∀to_search: addressing_mode.
271    bool_to_Prop (is_in ? p to_search) → bool_to_Prop (is_in ? (q @@ p) to_search).
272  # M # N # P # Q # TO_SEARCH
273  # H
274  elim Q
275  [ normalize
276    @ H
277  | # NN # PP # QQ # IH
278    normalize
279    cases (is_a PP TO_SEARCH)
280    [ normalize
281      %
282    | normalize
283      normalize in IH;
284      @ IH
285    ]
286  ]
287qed.
288
289corollary is_in_hd_tl:
290  ∀to_search: addressing_mode.
291  ∀hd: addressing_mode_tag.
292  ∀n: nat.
293  ∀v: Vector addressing_mode_tag n.
294    bool_to_Prop (is_in ? v to_search) → bool_to_Prop (is_in ? (hd:::v) to_search).
295  # TO_SEARCH # HD # N # V
296  elim V
297  [ # H
298    normalize in H;
299    cases H
300  | # NN # HHD # VV # IH # HH
301    > vector_cons_append
302    > (vector_cons_append ? ? HHD VV)
303    @ (is_in_monotonic_wrt_append ? 1 ([[HHD]]@@VV) [[HD]] TO_SEARCH)
304    @ HH
305  ]
306qed.
307 
308let rec list_addressing_mode_tags_elim
309  (n: nat) (l: Vector addressing_mode_tag (S n)) on l: (l → bool) → bool ≝
310  match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x').
311   (l → bool) → bool ] with
312  [ VEmpty      ⇒  true 
313  | VCons len hd tl ⇒ λP.
314    let process_hd ≝
315      match hd return λhd. ∀P: hd:::tl → bool. bool with
316      [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x))
317      | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x))
318      | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x))
319      | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x))
320      | acc_a ⇒ λP.P ACC_A
321      | acc_b ⇒ λP.P ACC_B
322      | dptr ⇒ λP.P DPTR
323      | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x))
324      | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x))
325      | acc_dptr ⇒ λP.P ACC_DPTR
326      | acc_pc ⇒ λP.P ACC_PC
327      | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR
328      | indirect_dptr ⇒ λP.P INDIRECT_DPTR
329      | carry ⇒ λP.P CARRY
330      | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x))
331      | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x))
332      | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x))
333      | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x))
334      | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x))
335      ]
336    in
337      andb (process_hd P)
338       (match len return λx. x = len → bool with
339         [ O ⇒ λprf. true
340         | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len))
341  ].
342  try %
343  [ 2: cases (sym_eq ??? prf); @tl
344  | generalize in match H; generalize in match tl; cases prf;
345    (* cases prf in tl H; : ??? WAS WORKING BEFORE *)
346    #tl
347    normalize in ⊢ (∀_: %. ?);
348    # H
349    whd
350    normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]);
351    cases (is_a hd (subaddressing_modeel y tl H)) whd // ]
352qed.
353
354definition product_elim ≝
355  λm, n: nat.
356  λv: Vector addressing_mode_tag (S m).
357  λq: Vector addressing_mode_tag (S n).
358  λP: (v × q) → bool.
359    list_addressing_mode_tags_elim ? v (λx. list_addressing_mode_tags_elim ? q (λy. P 〈x, y〉)).
360
361definition union_elim ≝
362  λA, B: Type[0].
363  λelimA: (A → bool) → bool.
364  λelimB: (B → bool) → bool.
365  λelimU: A ⊎ B → bool.
366    elimA (λa. elimB (λb. elimU (inl ? ? a) ∧ elimU (inr ? ? b))).
367
368(*                           
369definition preinstruction_elim: ∀P: preinstruction [[ relative ]] → bool. bool ≝
370  λP.
371    list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADD ? ACC_A addr)) ∧
372    list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADDC ? ACC_A addr)) ∧
373    list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (SUBB ? ACC_A addr)) ∧
374    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ; dptr ]] (λaddr. P (INC ? addr)) ∧
375    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (DEC ? addr)) ∧
376    list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (MUL ? ACC_A addr)) ∧
377    list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (DIV ? ACC_A addr)) ∧
378    list_addressing_mode_tags_elim ? [[ registr ; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧
379    list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CLR ? addr)) ∧
380    list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CPL ? addr)) ∧
381    P (DA ? ACC_A) ∧
382    bitvector_elim 8 (λr. P (JC ? (RELATIVE r))) ∧
383    bitvector_elim 8 (λr. P (JNC ? (RELATIVE r))) ∧
384    bitvector_elim 8 (λr. P (JZ ? (RELATIVE r))) ∧
385    bitvector_elim 8 (λr. P (JNZ ? (RELATIVE r))) ∧
386    bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JB ? (BIT_ADDR b) (RELATIVE r))))) ∧
387    bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JNB ? (BIT_ADDR b) (RELATIVE r))))) ∧
388    bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JBC ? (BIT_ADDR b) (RELATIVE r))))) ∧
389    list_addressing_mode_tags_elim ? [[ registr; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧
390    P (RL ? ACC_A) ∧
391    P (RLC ? ACC_A) ∧
392    P (RR ? ACC_A) ∧
393    P (RRC ? ACC_A) ∧
394    P (SWAP ? ACC_A) ∧
395    P (RET ?) ∧
396    P (RETI ?) ∧
397    P (NOP ?) ∧
398    bit_elim (λb. P (XCHD ? ACC_A (INDIRECT b))) ∧
399    list_addressing_mode_tags_elim ? [[ carry; bit_addr ]] (λaddr. P (SETB ? addr)) ∧
400    bitvector_elim 8 (λaddr. P (PUSH ? (DIRECT addr))) ∧
401    bitvector_elim 8 (λaddr. P (POP ? (DIRECT addr))) ∧
402    union_elim ? ? (product_elim ? ? [[ acc_a ]] [[ direct; data ]])
403                   (product_elim ? ? [[ registr; indirect ]] [[ data ]])
404                   (λd. bitvector_elim 8 (λb. P (CJNE ? d (RELATIVE b)))) ∧
405    list_addressing_mode_tags_elim ? [[ registr; direct; indirect ]] (λaddr. P (XCH ? ACC_A addr)) ∧
406    union_elim ? ? (product_elim ? ? [[acc_a]] [[ data ; registr ; direct ; indirect ]])
407                   (product_elim ? ? [[direct]] [[ acc_a ; data ]])
408                   (λd. P (XRL ? d)) ∧
409    union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]])
410                                   (product_elim ? ? [[direct]] [[ acc_a ; data ]]))
411                   (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]])
412                   (λd. P (ANL ? d)) ∧
413    union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; data ; direct ; indirect ]])
414                                   (product_elim ? ? [[direct]] [[ acc_a ; data ]]))
415                   (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]])
416                   (λd. P (ORL ? d)) ∧
417    union_elim ? ? (product_elim ? ? [[acc_a]] [[ ext_indirect ; ext_indirect_dptr ]])
418                   (product_elim ? ? [[ ext_indirect ; ext_indirect_dptr ]] [[acc_a]])
419                   (λd. P (MOVX ? d)) ∧
420    union_elim ? ? (
421      union_elim ? ? (
422        union_elim ? ? (
423          union_elim ? ? (
424            union_elim ? ?  (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]])
425                            (product_elim ? ? [[ registr ; indirect ]] [[ acc_a ; direct ; data ]]))
426                            (product_elim ? ? [[direct]] [[ acc_a ; registr ; direct ; indirect ; data ]]))
427                            (product_elim ? ? [[dptr]] [[data16]]))
428                            (product_elim ? ? [[carry]] [[bit_addr]]))
429                            (product_elim ? ? [[bit_addr]] [[carry]])
430                            (λd. P (MOV ? d)).
431  %
432qed.
433 
434definition instruction_elim: ∀P: instruction → bool. bool ≝
435  λP. (*
436    bitvector_elim 11 (λx. P (ACALL (ADDR11 x))) ∧
437    bitvector_elim 16 (λx. P (LCALL (ADDR16 x))) ∧
438    bitvector_elim 11 (λx. P (AJMP (ADDR11 x))) ∧
439    bitvector_elim 16 (λx. P (LJMP (ADDR16 x))) ∧ *)
440    bitvector_elim 8 (λx. P (SJMP (RELATIVE x))). (*  ∧
441    P (JMP INDIRECT_DPTR) ∧
442    list_addressing_mode_tags_elim ? [[ acc_dptr; acc_pc ]] (λa. P (MOVC ACC_A a)) ∧
443    preinstruction_elim (λp. P (RealInstruction p)). *)
444  %
445qed.
446
447
448axiom instruction_elim_complete:
449 ∀P. instruction_elim P = true → ∀i. P i = true.
450*)
451(*definition eq_instruction ≝
452  λi, j: instruction.
453    true.*)
454
455definition eq_addressing_mode: addressing_mode → addressing_mode → bool ≝
456  λa, b: addressing_mode.
457  match a with
458  [ DIRECT d ⇒
459    match b with
460    [ DIRECT e ⇒ eq_bv ? d e
461    | _ ⇒ false
462    ]
463  | INDIRECT b' ⇒
464    match b with
465    [ INDIRECT e ⇒ eq_b b' e
466    | _ ⇒ false
467    ]
468  | EXT_INDIRECT b' ⇒
469    match b with
470    [ EXT_INDIRECT e ⇒ eq_b b' e
471    | _ ⇒ false
472    ]
473  | REGISTER bv ⇒
474    match b with
475    [ REGISTER bv' ⇒ eq_bv ? bv bv'
476    | _ ⇒ false
477    ]
478  | ACC_A ⇒ match b with [ ACC_A ⇒ true | _ ⇒ false ]
479  | ACC_B ⇒ match b with [ ACC_B ⇒ true | _ ⇒ false ]
480  | DPTR ⇒ match b with [ DPTR ⇒ true | _ ⇒ false ]
481  | DATA b' ⇒
482    match b with
483    [ DATA e ⇒ eq_bv ? b' e
484    | _ ⇒ false
485    ]
486  | DATA16 w ⇒
487    match b with
488    [ DATA16 e ⇒ eq_bv ? w e
489    | _ ⇒ false
490    ]
491  | ACC_DPTR ⇒ match b with [ ACC_DPTR ⇒ true | _ ⇒ false ]
492  | ACC_PC ⇒ match b with [ ACC_PC ⇒ true | _ ⇒ false ]
493  | EXT_INDIRECT_DPTR ⇒ match b with [ EXT_INDIRECT_DPTR ⇒ true | _ ⇒ false ]
494  | INDIRECT_DPTR ⇒ match b with [ INDIRECT_DPTR ⇒ true | _ ⇒ false ]
495  | CARRY ⇒ match b with [ CARRY ⇒ true | _ ⇒ false ]
496  | BIT_ADDR b' ⇒
497    match b with
498    [ BIT_ADDR e ⇒ eq_bv ? b' e
499    | _ ⇒ false
500    ]
501  | N_BIT_ADDR b' ⇒
502    match b with
503    [ N_BIT_ADDR e ⇒ eq_bv ? b' e
504    | _ ⇒ false
505    ]
506  | RELATIVE n ⇒
507    match b with
508    [ RELATIVE e ⇒ eq_bv ? n e
509    | _ ⇒ false
510    ]
511  | ADDR11 w ⇒
512    match b with
513    [ ADDR11 e ⇒ eq_bv ? w e
514    | _ ⇒ false
515    ]
516  | ADDR16 w ⇒
517    match b with
518    [ ADDR16 e ⇒ eq_bv ? w e
519    | _ ⇒ false
520    ]
521  ].
522
523lemma eq_bv_refl:
524  ∀n, b.
525    eq_bv n b b = true.
526  #n #b cases b //
527qed.
528
529lemma eq_b_refl:
530  ∀b.
531    eq_b b b = true.
532  #b cases b //
533qed.
534
535lemma eq_addressing_mode_refl:
536  ∀a. eq_addressing_mode a a = true.
537  #a cases a try #arg1 try #arg2 try @eq_bv_refl try @eq_b_refl
538  try normalize %
539qed.
540 
541definition eq_sum: ∀A, B. (A → A → bool) → (B → B → bool) → (A ⊎ B) → (A ⊎ B) → bool ≝
542  λlt, rt, leq, req, left, right.
543    match left with
544    [ inl l ⇒
545      match right with
546      [ inl l' ⇒ leq l l'
547      | _ ⇒ false
548      ]
549    | inr r ⇒
550      match right with
551      [ inr r' ⇒ req r r'
552      | _ ⇒ false
553      ]
554    ].
555
556definition eq_prod: ∀A, B. (A → A → bool) → (B → B → bool) → (A × B) → (A × B) → bool ≝
557  λlt, rt, leq, req, left, right.
558    let 〈l, r〉 ≝ left in
559    let 〈l', r'〉 ≝ right in
560      leq l l' ∧ req r r'.
561
562definition eq_preinstruction: preinstruction [[relative]] → preinstruction [[relative]] → bool ≝
563  λi, j.
564  match i with
565  [ ADD arg1 arg2 ⇒
566    match j with
567    [ ADD arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
568    | _ ⇒ false
569    ]
570  | ADDC arg1 arg2 ⇒
571    match j with
572    [ ADDC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
573    | _ ⇒ false
574    ]
575  | SUBB arg1 arg2 ⇒
576    match j with
577    [ SUBB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
578    | _ ⇒ false
579    ]
580  | INC arg ⇒
581    match j with
582    [ INC arg' ⇒ eq_addressing_mode arg arg'
583    | _ ⇒ false
584    ]
585  | DEC arg ⇒
586    match j with
587    [ DEC arg' ⇒ eq_addressing_mode arg arg'
588    | _ ⇒ false
589    ]
590  | MUL arg1 arg2 ⇒
591    match j with
592    [ MUL arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
593    | _ ⇒ false
594    ]
595  | DIV arg1 arg2 ⇒
596    match j with
597    [ DIV arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
598    | _ ⇒ false
599    ]
600  | DA arg ⇒
601    match j with
602    [ DA arg' ⇒ eq_addressing_mode arg arg'
603    | _ ⇒ false
604    ]
605  | JC arg ⇒
606    match j with
607    [ JC arg' ⇒ eq_addressing_mode arg arg'
608    | _ ⇒ false
609    ]
610  | JNC arg ⇒
611    match j with
612    [ JNC arg' ⇒ eq_addressing_mode arg arg'
613    | _ ⇒ false
614    ]
615  | JB arg1 arg2 ⇒
616    match j with
617    [ JB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
618    | _ ⇒ false
619    ]
620  | JNB arg1 arg2 ⇒
621    match j with
622    [ JNB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
623    | _ ⇒ false
624    ]
625  | JBC arg1 arg2 ⇒
626    match j with
627    [ JBC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
628    | _ ⇒ false
629    ]
630  | JZ arg ⇒
631    match j with
632    [ JZ arg' ⇒ eq_addressing_mode arg arg'
633    | _ ⇒ false
634    ]
635  | JNZ arg ⇒
636    match j with
637    [ JNZ arg' ⇒ eq_addressing_mode arg arg'
638    | _ ⇒ false
639    ]
640  | CJNE arg1 arg2 ⇒
641    match j with
642    [ CJNE arg1' arg2' ⇒
643      let prod_eq_left ≝ eq_prod [[acc_a]] [[direct; data]] eq_addressing_mode eq_addressing_mode in
644      let prod_eq_right ≝ eq_prod [[registr; indirect]] [[data]] eq_addressing_mode eq_addressing_mode in
645      let arg1_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in
646        arg1_eq arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
647    | _ ⇒ false
648    ]
649  | DJNZ arg1 arg2 ⇒
650    match j with
651    [ DJNZ arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
652    | _ ⇒ false
653    ]
654  | CLR arg ⇒
655    match j with
656    [ CLR arg' ⇒ eq_addressing_mode arg arg'
657    | _ ⇒ false
658    ]
659  | CPL arg ⇒
660    match j with
661    [ CPL arg' ⇒ eq_addressing_mode arg arg'
662    | _ ⇒ false
663    ]
664  | RL arg ⇒
665    match j with
666    [ RL arg' ⇒ eq_addressing_mode arg arg'
667    | _ ⇒ false
668    ]
669  | RLC arg ⇒
670    match j with
671    [ RLC arg' ⇒ eq_addressing_mode arg arg'
672    | _ ⇒ false
673    ]
674  | RR arg ⇒
675    match j with
676    [ RR arg' ⇒ eq_addressing_mode arg arg'
677    | _ ⇒ false
678    ]
679  | RRC arg ⇒
680    match j with
681    [ RRC arg' ⇒ eq_addressing_mode arg arg'
682    | _ ⇒ false
683    ]
684  | SWAP arg ⇒
685    match j with
686    [ SWAP arg' ⇒ eq_addressing_mode arg arg'
687    | _ ⇒ false
688    ]
689  | SETB arg ⇒
690    match j with
691    [ SETB arg' ⇒ eq_addressing_mode arg arg'
692    | _ ⇒ false
693    ]
694  | PUSH arg ⇒
695    match j with
696    [ PUSH arg' ⇒ eq_addressing_mode arg arg'
697    | _ ⇒ false
698    ]
699  | POP arg ⇒
700    match j with
701    [ POP arg' ⇒ eq_addressing_mode arg arg'
702    | _ ⇒ false
703    ]
704  | XCH arg1 arg2 ⇒
705    match j with
706    [ XCH arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
707    | _ ⇒ false
708    ]
709  | XCHD arg1 arg2 ⇒
710    match j with
711    [ XCHD arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
712    | _ ⇒ false
713    ]
714  | RET ⇒ match j with [ RET ⇒ true | _ ⇒ false ]
715  | RETI ⇒ match j with [ RETI ⇒ true | _ ⇒ false ]
716  | NOP ⇒ match j with [ NOP ⇒ true | _ ⇒ false ]
717  | MOVX arg ⇒
718    match j with
719    [ MOVX arg' ⇒
720      let prod_eq_left ≝ eq_prod [[acc_a]] [[ext_indirect; ext_indirect_dptr]] eq_addressing_mode eq_addressing_mode in
721      let prod_eq_right ≝ eq_prod [[ext_indirect; ext_indirect_dptr]] [[acc_a]] eq_addressing_mode eq_addressing_mode in
722      let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in
723        sum_eq arg arg'
724    | _ ⇒ false
725    ]
726  | XRL arg ⇒
727    match j with
728    [ XRL arg' ⇒
729      let prod_eq_left ≝ eq_prod [[acc_a]] [[ data ; registr ; direct ; indirect ]] eq_addressing_mode eq_addressing_mode in
730      let prod_eq_right ≝ eq_prod [[direct]] [[ acc_a ; data ]] eq_addressing_mode eq_addressing_mode in
731      let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in
732        sum_eq arg arg'
733    | _ ⇒ false
734    ]
735  | ORL arg ⇒
736    match j with
737    [ ORL arg' ⇒
738      let prod_eq_left1 ≝ eq_prod [[acc_a]] [[ registr ; data ; direct ; indirect ]] eq_addressing_mode eq_addressing_mode in
739      let prod_eq_left2 ≝ eq_prod [[direct]] [[ acc_a; data ]] eq_addressing_mode eq_addressing_mode in
740      let prod_eq_left ≝ eq_sum ? ? prod_eq_left1 prod_eq_left2 in
741      let prod_eq_right ≝ eq_prod [[carry]] [[ bit_addr ; n_bit_addr]] eq_addressing_mode eq_addressing_mode in
742      let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in
743        sum_eq arg arg'
744    | _ ⇒ false
745    ]
746  | ANL arg ⇒
747    match j with
748    [ ANL arg' ⇒
749      let prod_eq_left1 ≝ eq_prod [[acc_a]] [[ registr ; direct ; indirect ; data ]] eq_addressing_mode eq_addressing_mode in
750      let prod_eq_left2 ≝ eq_prod [[direct]] [[ acc_a; data ]] eq_addressing_mode eq_addressing_mode in
751      let prod_eq_left ≝ eq_sum ? ? prod_eq_left1 prod_eq_left2 in
752      let prod_eq_right ≝ eq_prod [[carry]] [[ bit_addr ; n_bit_addr]] eq_addressing_mode eq_addressing_mode in
753      let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in
754        sum_eq arg arg'
755    | _ ⇒ false
756    ]
757  | MOV arg ⇒
758    match j with
759    [ MOV arg' ⇒
760      let prod_eq_6 ≝ eq_prod [[acc_a]] [[registr; direct; indirect; data]] eq_addressing_mode eq_addressing_mode in
761      let prod_eq_5 ≝ eq_prod [[registr; indirect]] [[acc_a; direct; data]] eq_addressing_mode eq_addressing_mode in
762      let prod_eq_4 ≝ eq_prod [[direct]] [[acc_a; registr; direct; indirect; data]] eq_addressing_mode eq_addressing_mode in
763      let prod_eq_3 ≝ eq_prod [[dptr]] [[data16]] eq_addressing_mode eq_addressing_mode in
764      let prod_eq_2 ≝ eq_prod [[carry]] [[bit_addr]] eq_addressing_mode eq_addressing_mode in
765      let prod_eq_1 ≝ eq_prod [[bit_addr]] [[carry]] eq_addressing_mode eq_addressing_mode in
766      let sum_eq_1 ≝ eq_sum ? ? prod_eq_6 prod_eq_5 in
767      let sum_eq_2 ≝ eq_sum ? ? sum_eq_1 prod_eq_4 in
768      let sum_eq_3 ≝ eq_sum ? ? sum_eq_2 prod_eq_3 in
769      let sum_eq_4 ≝ eq_sum ? ? sum_eq_3 prod_eq_2 in
770      let sum_eq_5 ≝ eq_sum ? ? sum_eq_4 prod_eq_1 in
771        sum_eq_5 arg arg'
772    | _ ⇒ false
773    ]
774  ].
775
776lemma eq_sum_refl:
777  ∀A, B: Type[0].
778  ∀leq, req.
779  ∀s.
780  ∀leq_refl: (∀t. leq t t = true).
781  ∀req_refl: (∀u. req u u = true).
782    eq_sum A B leq req s s = true.
783  #A #B #leq #req #s #leq_refl #req_refl
784  cases s whd in ⊢ (? → ??%?); //
785qed.
786
787lemma eq_prod_refl:
788  ∀A, B: Type[0].
789  ∀leq, req.
790  ∀s.
791  ∀leq_refl: (∀t. leq t t = true).
792  ∀req_refl: (∀u. req u u = true).
793    eq_prod A B leq req s s = true.
794  #A #B #leq #req #s #leq_refl #req_refl
795  cases s whd in ⊢ (? → ? → ??%?); #l #r >leq_refl normalize @req_refl
796qed.
797
798lemma eq_preinstruction_refl:
799  ∀i.
800    eq_preinstruction i i = true.
801  #i cases i try #arg1 try #arg2
802  try @eq_addressing_mode_refl
803  [1,2,3,4,5,6,7,8,10,16,17,18,19,20:
804    whd in ⊢ (??%?);
805    try %
806    >eq_addressing_mode_refl
807    >eq_addressing_mode_refl %
808  |13,15:
809    whd in ⊢ (??%?);
810    cases arg1
811    [*:
812      #arg1_left normalize nodelta
813      >eq_prod_refl [*: try % #argr @eq_addressing_mode_refl]
814    ]
815  |11,12:
816    whd in ⊢ (??%?);
817    cases arg1
818    [1:
819      #arg1_left normalize nodelta
820      >(eq_sum_refl …)
821      [1: % | 2,3: #arg @eq_prod_refl ]
822      @eq_addressing_mode_refl
823    |2:
824      #arg1_left normalize nodelta
825      @eq_prod_refl [*: @eq_addressing_mode_refl ]
826    |3:
827      #arg1_left normalize nodelta
828      >(eq_sum_refl …) [1: %
829      |2,3: #arg @eq_prod_refl #arg @eq_addressing_mode_refl ]
830    |4:
831      #arg1_left normalize nodelta
832      @eq_prod_refl [*: #arg @eq_addressing_mode_refl ]
833    ]
834  |14:
835    whd in ⊢ (??%?);
836    cases arg1
837    [ #arg1_left normalize nodelta
838      @eq_sum_refl
839      [1: #arg @eq_sum_refl
840        [1: #arg @eq_sum_refl
841          [1: #arg @eq_sum_refl
842            [1: #arg @eq_prod_refl
843              [*: @eq_addressing_mode_refl ]
844            |2: #arg @eq_prod_refl
845              [*: #arg @eq_addressing_mode_refl ]
846            ]
847          |2: #arg @eq_prod_refl
848            [*: #arg @eq_addressing_mode_refl ]
849          ]
850        |2: #arg @eq_prod_refl
851          [*: #arg @eq_addressing_mode_refl ]
852        ]
853      |2: #arg @eq_prod_refl
854        [*: #arg @eq_addressing_mode_refl ]
855      ]
856    |2: #arg1_right normalize nodelta
857        @eq_prod_refl [*: #arg @eq_addressing_mode_refl ]
858    ]
859  |*:
860    whd in ⊢ (??%?);
861    cases arg1
862    [*: #arg1 >eq_sum_refl
863      [1,4: normalize @eq_addressing_mode_refl
864      |2,3,5,6: #arg @eq_prod_refl
865        [*: #arg @eq_addressing_mode_refl ]
866      ]
867    ]
868  ]
869qed.
870
871definition eq_instruction: instruction → instruction → bool ≝
872  λi, j.
873  match i with
874  [ ACALL arg ⇒
875    match j with
876    [ ACALL arg' ⇒ eq_addressing_mode arg arg'
877    | _ ⇒ false
878    ]
879  | LCALL arg ⇒
880    match j with
881    [ LCALL arg' ⇒ eq_addressing_mode arg arg'
882    | _ ⇒ false
883    ]
884  | AJMP arg ⇒
885    match j with
886    [ AJMP arg' ⇒ eq_addressing_mode arg arg'
887    | _ ⇒ false
888    ]
889  | LJMP arg ⇒
890    match j with
891    [ LJMP arg' ⇒ eq_addressing_mode arg arg'
892    | _ ⇒ false
893    ]
894  | SJMP arg ⇒
895    match j with
896    [ SJMP arg' ⇒ eq_addressing_mode arg arg'
897    | _ ⇒ false
898    ]
899  | JMP arg ⇒
900    match j with
901    [ JMP arg' ⇒ eq_addressing_mode arg arg'
902    | _ ⇒ false
903    ]
904  | MOVC arg1 arg2 ⇒
905    match j with
906    [ MOVC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2'
907    | _ ⇒ false
908    ]
909  | RealInstruction instr ⇒
910    match j with
911    [ RealInstruction instr' ⇒ eq_preinstruction instr instr'
912    | _ ⇒ false
913    ]
914  ].
915 
916lemma eq_instruction_refl:
917  ∀i. eq_instruction i i = true.
918  #i cases i
919  [1,2,3,4,5,6: #arg1 @eq_addressing_mode_refl
920  |7: #arg1 #arg2
921      whd in ⊢ (??%?);
922      >eq_addressing_mode_refl
923      >eq_addressing_mode_refl
924      %
925  |8: #arg @eq_preinstruction_refl
926  ]
927qed.
928
929let rec vect_member
930  (A: Type[0]) (n: nat) (eq: A → A → bool)
931  (v: Vector A n) (a: A) on v: bool ≝
932  match v with
933  [ VEmpty          ⇒ false
934  | VCons len hd tl ⇒
935    eq hd a ∨ (vect_member A ? eq tl a)
936  ].
937
938let rec list_addressing_mode_tags_elim_prop
939  (n: nat)
940  (l: Vector addressing_mode_tag (S n))
941  on l:
942  ∀P: l → Prop.
943  ∀direct_a. ∀indirect_a. ∀ext_indirect_a. ∀register_a. ∀acc_a_a.
944  ∀acc_b_a. ∀dptr_a. ∀data_a. ∀data16_a. ∀acc_dptr_a. ∀acc_pc_a.
945  ∀ext_indirect_dptr_a. ∀indirect_dptr_a. ∀carry_a. ∀bit_addr_a.
946  ∀n_bit_addr_a. ∀relative_a. ∀addr11_a. ∀addr16_a.
947  ∀x: l. P x ≝
948  match l return
949    λy.
950      match y with
951      [ O    ⇒ λm: Vector addressing_mode_tag O. ∀prf: 0 = S n. True
952      | S y' ⇒ λl: Vector addressing_mode_tag (S y'). ∀prf: S y' = S n.∀P:l → Prop.
953               ∀direct_a: if vect_member … eq_a l direct then ∀x. P (DIRECT x) else True.
954               ∀indirect_a: if vect_member … eq_a l indirect then ∀x. P (INDIRECT x) else True.
955               ∀ext_indirect_a: if vect_member … eq_a l ext_indirect then ∀x. P (EXT_INDIRECT x) else True.
956               ∀register_a: if vect_member … eq_a l registr then ∀x. P (REGISTER x) else True.
957               ∀acc_a_a: if vect_member … eq_a l acc_a then P (ACC_A) else True.
958               ∀acc_b_a: if vect_member … eq_a l acc_b then P (ACC_B) else True.
959               ∀dptr_a: if vect_member … eq_a l dptr then P DPTR else True.
960               ∀data_a: if vect_member … eq_a l data then ∀x. P (DATA x) else True.
961               ∀data16_a: if vect_member … eq_a l data16 then ∀x. P (DATA16 x) else True.
962               ∀acc_dptr_a: if vect_member … eq_a l acc_dptr then P ACC_DPTR else True.
963               ∀acc_pc_a: if vect_member … eq_a l acc_pc then P ACC_PC else True.
964               ∀ext_indirect_dptr_a: if vect_member … eq_a l ext_indirect_dptr then P EXT_INDIRECT_DPTR else True.
965               ∀indirect_dptr_a: if vect_member … eq_a l indirect_dptr then P INDIRECT_DPTR else True.
966               ∀carry_a: if vect_member … eq_a l carry then P CARRY else True.
967               ∀bit_addr_a: if vect_member … eq_a l bit_addr then ∀x. P (BIT_ADDR x) else True.
968               ∀n_bit_addr_a: if vect_member … eq_a l n_bit_addr then ∀x. P (N_BIT_ADDR x) else True.
969               ∀relative_a: if vect_member … eq_a l relative then ∀x. P (RELATIVE x) else True.
970               ∀addr11_a: if vect_member … eq_a l addr11 then ∀x. P (ADDR11 x) else True.
971               ∀addr_16_a: if vect_member … eq_a l addr16 then ∀x. P (ADDR16 x) else True.
972               ∀x:l. P x
973      ] with
974  [ VEmpty          ⇒ λAbsurd. ⊥
975  | VCons len hd tl ⇒ λProof. ?
976  ] (refl ? (S n)). cases daemon. qed. (*
977  [ destruct(Absurd)
978  | # A1 # A2 # A3 # A4 # A5 # A6 # A7
979    # A8 # A9 # A10 # A11 # A12 # A13 # A14
980    # A15 # A16 # A17 # A18 # A19 # X
981    cases X
982    # SUB cases daemon ] qed.
983    cases SUB
984    [ # BYTE
985    normalize
986  ].
987 
988 
989(*    let prepare_hd ≝
990      match hd with
991      [ direct ⇒ λdirect_prf. ?
992      | indirect ⇒ λindirect_prf. ?
993      | ext_indirect ⇒ λext_indirect_prf. ?
994      | registr ⇒ λregistr_prf. ?
995      | acc_a ⇒ λacc_a_prf. ?
996      | acc_b ⇒ λacc_b_prf. ?
997      | dptr ⇒ λdptr_prf. ?
998      | data ⇒ λdata_prf. ?
999      | data16 ⇒ λdata16_prf. ?
1000      | acc_dptr ⇒ λacc_dptr_prf. ?
1001      | acc_pc ⇒ λacc_pc_prf. ?
1002      | ext_indirect_dptr ⇒ λext_indirect_prf. ?
1003      | indirect_dptr ⇒ λindirect_prf. ?
1004      | carry ⇒ λcarry_prf. ?
1005      | bit_addr ⇒ λbit_addr_prf. ?
1006      | n_bit_addr ⇒ λn_bit_addr_prf. ?
1007      | relative ⇒ λrelative_prf. ?
1008      | addr11 ⇒ λaddr11_prf. ?
1009      | addr16 ⇒ λaddr16_prf. ?
1010      ]
1011    in ? *)
1012  ].
1013  [ 1: destruct(absd)
1014  | 2: # A1 # A2 # A3 # A4 # A5 # A6
1015       # A7 # A8 # A9 # A10 # A11 # A12
1016       # A13 # A14 # A15 # A16 # A17 # A18
1017       # A19 *
1018  ].
1019
1020
1021  match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x').
1022   (l → bool) → bool ] with
1023  [ VEmpty      ⇒  true 
1024  | VCons len hd tl ⇒ λP.
1025    let process_hd ≝
1026      match hd return λhd. ∀P: hd:::tl → bool. bool with
1027      [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x))
1028      | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x))
1029      | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x))
1030      | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x))
1031      | acc_a ⇒ λP.P ACC_A
1032      | acc_b ⇒ λP.P ACC_B
1033      | dptr ⇒ λP.P DPTR
1034      | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x))
1035      | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x))
1036      | acc_dptr ⇒ λP.P ACC_DPTR
1037      | acc_pc ⇒ λP.P ACC_PC
1038      | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR
1039      | indirect_dptr ⇒ λP.P INDIRECT_DPTR
1040      | carry ⇒ λP.P CARRY
1041      | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x))
1042      | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x))
1043      | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x))
1044      | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x))
1045      | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x))
1046      ]
1047    in
1048      andb (process_hd P)
1049       (match len return λx. x = len → bool with
1050         [ O ⇒ λprf. true
1051         | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len))
1052  ].
1053  try %
1054  [ 2: cases (sym_eq ??? prf); @tl
1055  | generalize in match H; generalize in match tl; cases prf;
1056    (* cases prf in tl H; : ??? WAS WORKING BEFORE *)
1057    #tl
1058    normalize in ⊢ (∀_: %. ?)
1059    # H
1060    whd
1061    normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?])
1062    cases (is_a hd (subaddressing_modeel y tl H)) whd // ]
1063qed.
1064*)
1065
1066definition load_code_memory_aux ≝
1067 fold_left_i_aux … (
1068   λi, mem, v.
1069     insert … (bitvector_of_nat … i) v mem) (Stub Byte 16).
1070
1071lemma split_zero:
1072  ∀A,m.
1073  ∀v: Vector A m.
1074    〈[[]], v〉 = split A 0 m v.
1075  #A #m #v
1076  elim v
1077  [ %
1078  | #n #hd #tl #ih
1079    normalize in ⊢ (???%); %
1080  ]
1081qed.
1082
1083lemma Vector_O: ∀A. ∀v: Vector A 0. v ≃ VEmpty A.
1084 #A #v generalize in match (refl … 0); cases v in ⊢ (??%? → ?%%??); //
1085 #n #hd #tl #abs @⊥ destruct (abs)
1086qed.
1087
1088lemma Vector_Sn: ∀A. ∀n.∀v:Vector A (S n).
1089 ∃hd.∃tl.v ≃ VCons A n hd tl.
1090 #A #n #v generalize in match (refl … (S n)); cases v in ⊢ (??%? → ??(λ_.??(λ_.?%%??)));
1091 [ #abs @⊥ destruct (abs)
1092 | #m #hd #tl #EQ <(injective_S … EQ) %[@hd] %[@tl] // ]
1093qed.
1094
1095lemma vector_append_zero:
1096  ∀A,m.
1097  ∀v: Vector A m.
1098  ∀q: Vector A 0.
1099    v = q@@v.
1100  #A #m #v #q
1101  >(Vector_O A q) %
1102qed.
1103
1104lemma prod_eq_left:
1105  ∀A: Type[0].
1106  ∀p, q, r: A.
1107    p = q → 〈p, r〉 = 〈q, r〉.
1108  #A #p #q #r #hyp
1109  >hyp %
1110qed.
1111
1112lemma prod_eq_right:
1113  ∀A: Type[0].
1114  ∀p, q, r: A.
1115    p = q → 〈r, p〉 = 〈r, q〉.
1116  #A #p #q #r #hyp
1117  >hyp %
1118qed.
1119
1120corollary prod_vector_zero_eq_left:
1121  ∀A, n.
1122  ∀q: Vector A O.
1123  ∀r: Vector A n.
1124    〈q, r〉 = 〈[[ ]], r〉.
1125  #A #n #q #r
1126  generalize in match (Vector_O A q …);
1127  #hyp
1128  >hyp in ⊢ (??%?);
1129  %
1130qed.
1131
1132axiom split_succ:
1133  ∀A, m, n.
1134  ∀l: Vector A m.
1135  ∀r: Vector A n.
1136  ∀v: Vector A (m + n).
1137  ∀hd: A.
1138    v = l@@r → (〈l, r〉 = split A m n v → 〈hd:::l, r〉 = split A (S m) n (hd:::v)).
1139(*
1140  #A #m
1141  elim m
1142  [ #n #l #r #v #hd #equal #hyp
1143    normalize >(Vector_O A l) >equal
1144    >(Vector_O A l) %
1145  | #n' #ih #n #l #r #v #hd
1146    #equal #hyp
1147    cases(Vector_Sn A n' l)
1148    #hd' #exists
1149    cases exists #tl #jmeq
1150    >jmeq *)
1151
1152lemma split_prod:
1153  ∀A,m,n.
1154  ∀p: Vector A (m + n).
1155  ∀v: Vector A m.
1156  ∀q: Vector A n.
1157    p = v@@q → 〈v, q〉 = split A m n p.
1158  #A #m
1159  elim m
1160  [ #n #p #v #q #hyp
1161    >hyp <(vector_append_zero A n q v)
1162    >(prod_vector_zero_eq_left A …)
1163    @split_zero
1164  | #r #ih #n #p #v #q #hyp
1165    >hyp
1166    cases (Vector_Sn A r v)
1167    #hd #exists
1168    cases exists
1169    #tl #jmeq >jmeq
1170    @split_succ [1: % |2: @ih % ]
1171  ]
1172qed.
1173
1174(*
1175lemma split_prod_exists:
1176  ∀A, m, n.
1177  ∀p: Vector A (m + n).
1178  ∃v: Vector A m.
1179  ∃q: Vector A n.
1180    〈v, q〉 = split A m n p.
1181  #A #m #n #p
1182  elim m
1183  @ex_intro
1184  [1:
1185  |2: @ex_intro
1186      [1:
1187      |2:
1188      ]
1189  ]
1190*)
1191
1192axiom split_elim:
1193 ∀A,l,m,v.∀P: (Vector A l) × (Vector A m) → Prop.
1194  (∀vl,vm. v = vl@@vm → P 〈vl,vm〉) → P (split A l m v).
1195(*  #A #l #m #v #P #hyp
1196  normalize
1197  <(split_prod A l m v ? ? ?)
1198*)
1199
1200example half_add_SO:
1201 ∀pc.
1202 \snd (half_add 16 (bitvector_of_nat … pc) (bitvector_of_nat … 1)) = bitvector_of_nat … (S pc).
1203 cases daemon.
1204qed.
1205
1206(*
1207axiom not_eqvb_S:
1208 ∀pc.
1209 (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S pc))).
1210
1211axiom not_eqvb_SS:
1212 ∀pc.
1213 (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S (S pc)))).
1214 
1215axiom bitvector_elim_complete:
1216 ∀n,P. bitvector_elim n P = true → ∀bv. P bv.
1217
1218lemma bitvector_elim_complete':
1219 ∀n,P. bitvector_elim n P = true → ∀bv. P bv = true.
1220 #n #P #H generalize in match (bitvector_elim_complete … H) #K #bv
1221 generalize in match (K bv) normalize cases (P bv) normalize // #abs @⊥ //
1222qed.
1223*)
1224
1225(*
1226lemma andb_elim':
1227 ∀b1,b2. (b1 = true) → (b2 = true) → (b1 ∧ b2) = true.
1228 #b1 #b2 #H1 #H2 @andb_elim cases b1 in H1; normalize //
1229qed.
1230*)
1231
1232let rec encoding_check (code_memory: BitVectorTrie Byte 16) (pc: Word) (final_pc: Word)
1233                       (encoding: list Byte) on encoding: Prop ≝
1234  match encoding with
1235  [ nil ⇒ final_pc = pc
1236  | cons hd tl ⇒
1237    let 〈new_pc, byte〉 ≝ next code_memory pc in
1238      hd = byte ∧ encoding_check code_memory new_pc final_pc tl
1239  ].
1240
1241lemma encoding_check_append: ∀code_memory,final_pc,l1,pc,l2.
1242 encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … final_pc) (l1@l2) →
1243  let intermediate_pc ≝ pc + length … l1 in
1244   encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … intermediate_pc) l1 ∧
1245    encoding_check code_memory (bitvector_of_nat … intermediate_pc) (bitvector_of_nat … final_pc) l2.
1246 #code_memory #final_pc #l1 elim l1
1247  [ #pc #l2 whd in ⊢ (????% → ?); #H <plus_n_O whd whd in ⊢ (?%?); /2/
1248  | #hd #tl #IH #pc #l2 * #H1 #H2 >half_add_SO in H2; #H2 cases (IH … H2) <plus_n_Sm
1249    #K1 #K2 % [2:@K2] whd % // >half_add_SO @K1 ]
1250qed.
1251
1252axiom bitvector_3_elim_prop:
1253 ∀P: BitVector 3 → Prop.
1254  P [[false;false;false]] → P [[false;false;true]] → P [[false;true;false]] →
1255  P [[false;true;true]] → P [[true;false;false]] → P [[true;false;true]] →
1256  P [[true;true;false]] → P [[true;true;true]] → ∀v. P v.
1257
1258definition ticks_of_instruction ≝
1259 λi.
1260  let trivial_code_memory ≝ assembly1 i in
1261  let trivial_status ≝ load_code_memory trivial_code_memory in
1262   \snd (fetch trivial_status (zero ?)).
1263
1264lemma fetch_assembly:
1265  ∀pc,i,code_memory,assembled.
1266    assembled = assembly1 i →
1267      let len ≝ length … assembled in
1268      encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled →
1269      let fetched ≝ fetch code_memory (bitvector_of_nat … pc) in
1270      let 〈instr_pc, ticks〉 ≝ fetched in
1271      let 〈instr,pc'〉 ≝ instr_pc in
1272       (eq_instruction instr i ∧ eqb ticks (ticks_of_instruction instr) ∧ eq_bv … pc' (bitvector_of_nat … (pc + len))) = true.
1273 #pc #i #code_memory #assembled cases i [8: *]
1274 [16,20,29: * * |18,19: * * [1,2,4,5: *] |28: * * [1,2: * [1,2: * [1,2: * [1,2: *]]]]]
1275 [47,48,49:
1276 |*: #arg @(list_addressing_mode_tags_elim_prop … arg) whd try % -arg
1277  [2,3,5,7,10,12,16,17,18,21,25,26,27,30,31,32,37,38,39,40,41,42,43,44,45,48,51,58,
1278   59,60,63,64,65,66,67: #ARG]]
1279 [4,5,6,7,8,9,10,11,12,13,22,23,24,27,28,39,40,41,42,43,44,45,46,47,48,49,50,51,52,
1280  56,57,69,70,72,73,75: #arg2 @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2
1281  [1,2,4,7,9,10,12,13,15,16,17,18,20,22,23,24,25,26,27,28,29,30,31,32,33,36,37,38,
1282   39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,
1283   68,69,70,71: #ARG2]]
1284 [1,2,19,20: #arg3 @(list_addressing_mode_tags_elim_prop … arg3) whd try % -arg3 #ARG3]
1285 normalize in ⊢ (???% → ?);
1286 [92,94,42,93,95: @split_elim #vl #vm #E >E -E; [2,4: @(bitvector_3_elim_prop … vl)]
1287  normalize in ⊢ (???% → ?);]
1288 #H >H * #H1 try (whd in ⊢ (% → ?); * #H2)
1289 try (whd in ⊢ (% → ?); * #H3) whd in ⊢ (% → ?); #H4
1290 [ whd in match fetch; normalize nodelta <H1 ] cases daemon
1291 (*XXX
1292   
1293 whd in ⊢ (let fetched ≝ ??% in ?) <H1 whd in ⊢ (let fetched ≝ % in ?)
1294 [17,18,19,20,21,22,23,24,25,26,31,34,35,36,37,38: <H3]
1295 [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
1296  30,31,32,33,34,35,36,37,38,39,40,43,45,48,49,52,53,54,55,56,57,60,61,62,65,66,
1297  69,70,73,74,78,80,81,84,85,95,98,101,102,103,104,105,106,107,108,109,110: <H2]
1298 whd >eq_instruction_refl >H4 @eq_bv_refl*)
1299qed.
1300
1301let rec fetch_many code_memory final_pc pc expected on expected: Prop ≝
1302 match expected with
1303  [ nil ⇒ eq_bv … pc final_pc = true
1304  | cons i tl ⇒
1305     let fetched ≝ fetch code_memory pc in
1306     let 〈instr_pc, ticks〉 ≝ fetched in
1307     let 〈instr,pc'〉 ≝ instr_pc in
1308      eq_instruction instr i = true ∧
1309      ticks = (ticks_of_instruction i) ∧
1310      fetch_many code_memory final_pc pc' tl].
1311
1312lemma option_destruct_Some: ∀A,a,b. Some A a = Some A b → a=b.
1313 #A #a #b #EQ destruct //
1314qed.
1315
1316axiom eq_instruction_to_eq:
1317  ∀i1,i2. eq_instruction i1 i2 = true → i1 = i2.
1318               
1319lemma fetch_assembly_pseudo':
1320 ∀lookup_labels.∀pol:policy_type lookup_labels.∀ppc,lookup_datalabels.
1321  ∀pi,code_memory,len,assembled,instructions,pc.
1322   let expansion ≝ pol ppc in
1323   instructions = expand_pseudo_instruction lookup_labels ppc expansion lookup_datalabels pi →
1324    〈len,assembled〉 = assembly_1_pseudoinstruction lookup_labels pol ppc lookup_datalabels pi →
1325     encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled →
1326      fetch_many code_memory (bitvector_of_nat … (pc + len)) (bitvector_of_nat … pc) instructions.
1327 #lookup_labels #pol #ppc #lookup_datalabels #pi #code_memory #len #assembled #instructions #pc
1328 #EQ1 whd in ⊢ (???% → ?); <EQ1 whd in ⊢ (???% → ?); #EQ2
1329 cases (pair_destruct ?????? EQ2) -EQ2; #EQ2a #EQ2b
1330 >EQ2a >EQ2b -EQ2a -EQ2b;
1331  generalize in match (pc + |flatten … (map … assembly1 instructions)|); #final_pc
1332  generalize in match pc; elim instructions
1333  [ #pc whd in ⊢ (% → %); #H >H @eq_bv_refl
1334  | #i #tl #IH #pc #H whd cases (encoding_check_append … H); -H; #H1 #H2 whd
1335    generalize in match (fetch_assembly pc i code_memory … (refl …) H1);
1336    cases (fetch code_memory (bitvector_of_nat … pc)) #newi_pc #ticks whd in ⊢ (% → %);
1337    cases newi_pc #newi #newpc whd in ⊢ (% → %); #K cases (conjunction_true … K) -K; #K1
1338    cases (conjunction_true … K1) -K1; #K1 #K2 #K3 % try %
1339    [ @K1 | @eqb_true_to_eq <(eq_instruction_to_eq … K1) @K2 | >(eq_bv_eq … K3) @IH @H2 ]
1340qed.
1341
1342axiom bitvector_of_nat_nat_of_bitvector:
1343  ∀n,v.
1344    bitvector_of_nat n (nat_of_bitvector n v) = v.
1345
1346(* CSC: soo long next one; can we merge with previous one now? *)
1347lemma fetch_assembly_pseudo:
1348  ∀program:pseudo_assembly_program.
1349  let lookup_labels ≝ λx:Identifier.(address_of_word_labels_code_mem (\snd  program) x) in
1350  ∀pol:(policy program).∀ppc.∀code_memory.
1351  let lookup_datalabels ≝ λx:Identifier.lookup_def … (construct_datalabels (\fst  program)) x (zero 16) in
1352  let pc ≝ sigma program pol ppc in
1353  let pi ≝  \fst  (fetch_pseudo_instruction (\snd program) ppc) in
1354  let instructions ≝ expand_pseudo_instruction lookup_labels ppc (pol lookup_labels ppc) lookup_datalabels pi in
1355  let 〈len,assembled〉 ≝ assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels pi in
1356    encoding_check code_memory pc (bitvector_of_nat … (nat_of_bitvector ? pc + len)) assembled →
1357     fetch_many code_memory (bitvector_of_nat … (nat_of_bitvector ? pc + len)) pc instructions.
1358 #program letin lookup_labels ≝ (λx.?) #pol #ppc #code_memory
1359 letin lookup_datalabels ≝ (λx.?)
1360 letin pc ≝ (sigma ???) letin pi ≝ (fst ???) 
1361 letin instructions ≝ (expand_pseudo_instruction ?????)
1362 @pair_elim #len #assembled #EQ1 #H
1363 generalize in match
1364  (fetch_assembly_pseudo' lookup_labels ((pi1 ?? pol) lookup_labels) ppc lookup_datalabels pi code_memory len
1365   assembled instructions (nat_of_bitvector ? pc)) in ⊢ ?;
1366  >bitvector_of_nat_nat_of_bitvector >EQ1 normalize nodelta
1367  #X @X //
1368qed.
1369
1370(* This is a trivial consequence of fetch_assembly + the proof that the
1371   function that load the code in memory is correct. The latter is based
1372   on missing properties from the standard library on the BitVectorTrie
1373   data structrure. *)
1374axiom assembly_ok:
1375 ∀program,pol,assembled,costs'.
1376  let 〈labels,costs〉 ≝ build_maps program pol in
1377  〈assembled,costs'〉 = assembly program pol →
1378  costs = costs' ∧
1379  let code_memory ≝ load_code_memory assembled in
1380  let preamble ≝ \fst program in
1381  let datalabels ≝ construct_datalabels preamble in
1382  let lookup_labels ≝ λx. address_of_word_labels_code_mem (\snd program) x in
1383  let lookup_datalabels ≝ λx. lookup_def ?? datalabels x (zero ?) in
1384  ∀ppc.
1385  let pi_newppc ≝ fetch_pseudo_instruction (\snd program) ppc in
1386   ∀len,assembledi.
1387     〈len,assembledi〉 = assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels (\fst pi_newppc) →
1388      encoding_check code_memory (sigma program pol ppc) (bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len)) assembledi ∧
1389       sigma program pol (\snd pi_newppc) = bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len).
1390
1391lemma fetch_assembly_pseudo2:
1392 ∀program,pol,ppc.
1393(*  let 〈labels,costs〉 ≝ build_maps program pol in *)
1394  let assembled ≝ \fst (assembly program pol) in
1395  let code_memory ≝ load_code_memory assembled in
1396  let data_labels ≝ construct_datalabels (\fst program) in
1397  let lookup_labels ≝ λx.address_of_word_labels_code_mem (\snd program) x in
1398  let lookup_datalabels ≝ λx. lookup_def ? ? data_labels x (zero ?) in
1399  let 〈pi,newppc〉 ≝ fetch_pseudo_instruction (\snd program) ppc in
1400  let instructions ≝ expand_pseudo_instruction lookup_labels ppc (pol lookup_labels ppc) lookup_datalabels pi in
1401   fetch_many code_memory (sigma program pol newppc) (sigma program pol ppc) instructions.
1402 * #preamble #instr_list #pol #ppc
1403 letin assembled ≝ (\fst (assembly 〈preamble,instr_list〉 pol))
1404 letin code_memory ≝ (load_code_memory assembled)
1405 letin data_labels ≝ (construct_datalabels preamble)
1406 letin lookup_labels ≝ (λx. address_of_word_labels_code_mem instr_list x)
1407 letin lookup_datalabels ≝ (λx. lookup_def ? ? data_labels x (zero ?))
1408 @pair_elim #pi #newppc #EQ1 change with (fetch_pseudo_instruction instr_list ? = ?) in EQ1;
1409 generalize in match (assembly_ok ? pol assembled (\snd (assembly 〈preamble,instr_list〉 pol)));
1410 @pair_elim #labels #costs #EQ2 <eq_pair_fst_snd
1411 #H cases (H (refl \ldots)) -H; #EQ3
1412 generalize in match (refl … (assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels ?));
1413 [ cases (assembly_1_pseudoinstruction ?????) in ⊢ (???% → ?); #len #assembledi #EQ4
1414   #H cases (H ppc len assembledi ?) [2: <EQ4 %] -H; #H1 #H2
1415   (* XXX JPB: attention to lookup_labels *)
1416   generalize in match (fetch_assembly_pseudo 〈preamble,instr_list〉 pol ppc (load_code_memory assembled)) in ⊢ ?;
1417   >EQ4; #H generalize in match (H H1) in ⊢ ?; -H >(pair_destruct_2 ????? (sym_eq … EQ1))
1418   >H2 >EQ1 #K @K
1419qed.
1420
1421(* OLD?
1422definition assembly_specification:
1423  ∀assembly_program: pseudo_assembly_program.
1424  ∀code_mem: BitVectorTrie Byte 16. Prop ≝
1425  λpseudo_assembly_program.
1426  λcode_mem.
1427    ∀pc: Word.
1428      let 〈preamble, instr_list〉 ≝ pseudo_assembly_program in
1429      let 〈pre_instr, pre_new_pc〉 ≝ fetch_pseudo_instruction instr_list pc in
1430      let labels ≝ λx. sigma' pseudo_assembly_program (address_of_word_labels_code_mem instr_list x) in
1431      let datalabels ≝ λx. sigma' pseudo_assembly_program (lookup ? ? x (construct_datalabels preamble) (zero ?)) in
1432      let pre_assembled ≝ assembly_1_pseudoinstruction pseudo_assembly_program
1433       (sigma' pseudo_assembly_program pc) labels datalabels pre_instr in
1434      match pre_assembled with
1435       [ None ⇒ True
1436       | Some pc_code ⇒
1437          let 〈new_pc,code〉 ≝ pc_code in
1438           encoding_check code_mem pc (sigma' pseudo_assembly_program pre_new_pc) code ].
1439
1440axiom assembly_meets_specification:
1441  ∀pseudo_assembly_program.
1442    match assembly pseudo_assembly_program with
1443    [ None ⇒ True
1444    | Some code_mem_cost ⇒
1445      let 〈code_mem, cost〉 ≝ code_mem_cost in
1446        assembly_specification pseudo_assembly_program (load_code_memory code_mem)
1447    ].
1448(*
1449  # PROGRAM
1450  [ cases PROGRAM
1451    # PREAMBLE
1452    # INSTR_LIST
1453    elim INSTR_LIST
1454    [ whd
1455      whd in ⊢ (∀_. %)
1456      # PC
1457      whd
1458    | # INSTR
1459      # INSTR_LIST_TL
1460      # H
1461      whd
1462      whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?])
1463    ]
1464  | cases not_implemented
1465  ] *)
1466*)
1467
1468definition internal_pseudo_address_map ≝ list (BitVector 8).
1469
1470axiom low_internal_ram_of_pseudo_low_internal_ram:
1471 ∀M:internal_pseudo_address_map.∀ram:BitVectorTrie Byte 7.BitVectorTrie Byte 7.
1472
1473axiom high_internal_ram_of_pseudo_high_internal_ram:
1474 ∀M:internal_pseudo_address_map.∀ram:BitVectorTrie Byte 7.BitVectorTrie Byte 7.
1475
1476axiom low_internal_ram_of_pseudo_internal_ram_hit:
1477 ∀M:internal_pseudo_address_map.∀s:PseudoStatus.∀pol:policy (code_memory … s).∀addr:BitVector 7.
1478  member ? (eq_bv 8) (false:::addr) M = true →
1479   let ram ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … s) in
1480   let pbl ≝ lookup ? 7 addr (low_internal_ram ? s) (zero 8) in
1481   let pbu ≝ lookup ? 7 (\snd (half_add ? addr (bitvector_of_nat 7 1))) (low_internal_ram ? s) (zero 8) in
1482   let bl ≝ lookup ? 7 addr ram (zero 8) in
1483   let bu ≝ lookup ? 7 (\snd (half_add ? addr (bitvector_of_nat 7 1))) ram (zero 8) in
1484    bu@@bl = sigma (code_memory … s) pol (pbu@@pbl).
1485
1486(* changed from add to sub *)
1487axiom low_internal_ram_of_pseudo_internal_ram_miss:
1488 ∀T.∀M:internal_pseudo_address_map.∀s:PreStatus T.∀addr:BitVector 7.
1489  let ram ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … s) in
1490  let 〈Saddr,flags〉 ≝ sub_7_with_carry addr (bitvector_of_nat 7 1) false in
1491  let carr ≝ get_index_v ? ? flags 1 ? in
1492  carr = false →
1493  member ? (eq_bv 8) (false:::Saddr) M = false →
1494   member ? (eq_bv 8) (false:::addr) M = false →
1495    lookup ? 7 addr ram (zero ?) = lookup ? 7 addr (low_internal_ram … s) (zero ?).
1496  //
1497qed.
1498
1499definition addressing_mode_ok ≝
1500 λT.λM:internal_pseudo_address_map.λs:PreStatus T.
1501  λaddr:addressing_mode.
1502   match addr with
1503    [ DIRECT d ⇒
1504       ¬(member ? (eq_bv 8) d M) ∧
1505       ¬(member ? (eq_bv 8) (\fst (sub_8_with_carry d (bitvector_of_nat 8 1) false)) M)
1506    | INDIRECT i ⇒
1507       let d ≝ get_register ? s [[false;false;i]] in
1508       ¬(member ? (eq_bv 8) d M) ∧
1509       ¬(member ? (eq_bv 8) (\fst (sub_8_with_carry d (bitvector_of_nat 8 1) false)) M)
1510    | EXT_INDIRECT _ ⇒ true
1511    | REGISTER _ ⇒ true
1512    | ACC_A ⇒ true
1513    | ACC_B ⇒ true
1514    | DPTR ⇒ true
1515    | DATA _ ⇒ true
1516    | DATA16 _ ⇒ true
1517    | ACC_DPTR ⇒ true
1518    | ACC_PC ⇒ true
1519    | EXT_INDIRECT_DPTR ⇒ true
1520    | INDIRECT_DPTR ⇒ true
1521    | CARRY ⇒ true
1522    | BIT_ADDR _ ⇒ ¬true (* TO BE COMPLETED *)
1523    | N_BIT_ADDR _ ⇒ ¬true (* TO BE COMPLETED *)
1524    | RELATIVE _ ⇒ true
1525    | ADDR11 _ ⇒ true
1526    | ADDR16 _ ⇒ true ].
1527   
1528definition next_internal_pseudo_address_map0 ≝
1529  λT.
1530  λfetched.
1531  λM: internal_pseudo_address_map.
1532  λs: PreStatus T.
1533   match fetched with
1534    [ Comment _ ⇒ Some ? M
1535    | Cost _ ⇒ Some … M
1536    | Jmp _ ⇒ Some … M
1537    | Call _ ⇒
1538       Some … (\snd (half_add ? (get_8051_sfr … s SFR_SP) (bitvector_of_nat 8 1))::M)
1539    | Mov _ _ ⇒ Some … M
1540    | Instruction instr ⇒
1541       match instr with
1542        [ ADD addr1 addr2 ⇒
1543           if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then
1544            Some ? M
1545           else
1546            None ?
1547        | ADDC addr1 addr2 ⇒
1548           if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then
1549            Some ? M
1550           else
1551            None ?
1552        | SUBB addr1 addr2 ⇒
1553           if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then
1554            Some ? M
1555           else
1556            None ?       
1557        | _ ⇒ (* TO BE COMPLETED *) Some ? M ]].
1558 
1559
1560definition next_internal_pseudo_address_map ≝
1561 λM:internal_pseudo_address_map.
1562  λs:PseudoStatus.
1563    next_internal_pseudo_address_map0 ?
1564     (\fst (fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s))) M s.
1565   
1566definition status_of_pseudo_status:
1567 internal_pseudo_address_map → ∀ps:PseudoStatus. policy (code_memory … ps) → Status ≝
1568 λM,ps,pol.
1569  let pap ≝ code_memory … ps in
1570  let p ≝ assembly pap pol in
1571  let cm ≝ load_code_memory (\fst p) in
1572  let pc ≝ sigma pap pol (program_counter ? ps) in
1573  let lir ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps) in
1574  let hir ≝ high_internal_ram_of_pseudo_high_internal_ram M (high_internal_ram … ps) in
1575     mk_PreStatus (BitVectorTrie Byte 16)
1576      cm
1577      lir
1578      hir
1579      (external_ram … ps)
1580      pc
1581      (special_function_registers_8051 … ps)
1582      (special_function_registers_8052 … ps)
1583      (p1_latch … ps)
1584      (p3_latch … ps)
1585      (clock … ps).
1586
1587(*
1588definition write_at_stack_pointer':
1589 ∀M. ∀ps: PreStatus M. Byte → Σps':PreStatus M.(code_memory … ps = code_memory … ps') ≝
1590  λM: Type[0].
1591  λs: PreStatus M.
1592  λv: Byte.
1593    let 〈 nu, nl 〉 ≝ split … 4 4 (get_8051_sfr ? s SFR_SP) in
1594    let bit_zero ≝ get_index_v… nu O ? in
1595    let bit_1 ≝ get_index_v… nu 1 ? in
1596    let bit_2 ≝ get_index_v… nu 2 ? in
1597    let bit_3 ≝ get_index_v… nu 3 ? in
1598      if bit_zero then
1599        let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl)
1600                              v (low_internal_ram ? s) in
1601          set_low_internal_ram ? s memory
1602      else
1603        let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl)
1604                              v (high_internal_ram ? s) in
1605          set_high_internal_ram ? s memory.
1606  [ cases l0 %
1607  |2,3,4,5: normalize repeat (@ le_S_S) @ le_O_n ]
1608qed.
1609
1610definition execute_1_pseudo_instruction': (Word → nat) → ∀ps:PseudoStatus.
1611 Σps':PseudoStatus.(code_memory … ps = code_memory … ps')
1612
1613  λticks_of.
1614  λs.
1615  let 〈instr, pc〉 ≝ fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s) in
1616  let ticks ≝ ticks_of (program_counter ? s) in
1617  let s ≝ set_clock ? s (clock ? s + ticks) in
1618  let s ≝ set_program_counter ? s pc in
1619    match instr with
1620    [ Instruction instr ⇒
1621       execute_1_preinstruction … (λx, y. address_of_word_labels y x) instr s
1622    | Comment cmt ⇒ s
1623    | Cost cst ⇒ s
1624    | Jmp jmp ⇒ set_program_counter ? s (address_of_word_labels s jmp)
1625    | Call call ⇒
1626      let a ≝ address_of_word_labels s call in
1627      let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in
1628      let s ≝ set_8051_sfr ? s SFR_SP new_sp in
1629      let 〈pc_bu, pc_bl〉 ≝ split ? 8 8 (program_counter ? s) in
1630      let s ≝ write_at_stack_pointer' ? s pc_bl in
1631      let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in
1632      let s ≝ set_8051_sfr ? s SFR_SP new_sp in
1633      let s ≝ write_at_stack_pointer' ? s pc_bu in
1634        set_program_counter ? s a
1635    | Mov dptr ident ⇒
1636       set_arg_16 ? s (get_arg_16 ? s (DATA16 (address_of_word_labels s ident))) dptr
1637    ].
1638 [
1639 |2,3,4: %
1640 | <(sig2 … l7) whd in ⊢ (??? (??%)) <(sig2 … l5) %
1641 |
1642 | %
1643 ]
1644 cases not_implemented
1645qed.
1646*)
1647
1648axiom execute_1_pseudo_instruction_preserves_code_memory:
1649 ∀ticks_of,ps.
1650  code_memory … (execute_1_pseudo_instruction ticks_of ps) = code_memory … ps.
1651
1652(*
1653lemma execute_code_memory_unchanged:
1654 ∀ticks_of,ps. code_memory ? ps = code_memory ? (execute_1_pseudo_instruction ticks_of ps).
1655 #ticks #ps whd in ⊢ (??? (??%))
1656 cases (fetch_pseudo_instruction (\snd (code_memory pseudo_assembly_program ps))
1657  (program_counter pseudo_assembly_program ps)) #instr #pc
1658 whd in ⊢ (??? (??%)) cases instr
1659  [ #pre cases pre
1660     [ #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1661       cases (split ????) #z1 #z2 %
1662     | #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1663       cases (split ????) #z1 #z2 %
1664     | #a1 #a2 whd in ⊢ (??? (??%)) cases (sub_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1665       cases (split ????) #z1 #z2 %
1666     | #a1 whd in ⊢ (??? (??%)) cases a1 #x #H whd in ⊢ (??? (??%)) cases x
1667       [ #x1 whd in ⊢ (??? (??%))
1668     | *: cases not_implemented
1669     ]
1670  | #comment %
1671  | #cost %
1672  | #label %
1673  | #label whd in ⊢ (??? (??%)) cases (half_add ???) #x1 #x2 whd in ⊢ (??? (??%))
1674    cases (split ????) #y1 #y2 whd in ⊢ (??? (??%)) cases (half_add ???) #z1 #z2
1675    whd in ⊢ (??? (??%)) whd in ⊢ (??? (??%)) cases (split ????) #w1 #w2
1676    whd in ⊢ (??? (??%)) cases (get_index_v bool ????) whd in ⊢ (??? (??%))
1677    (* CSC: ??? *)
1678  | #dptr #label (* CSC: ??? *)
1679  ]
1680  cases not_implemented
1681qed.
1682*)
1683
1684(* DEAD CODE?
1685lemma status_of_pseudo_status_failure_depends_only_on_code_memory:
1686 ∀M:internal_pseudo_address_map.
1687 ∀ps,ps': PseudoStatus.
1688 ∀pol.
1689  ∀prf:code_memory … ps = code_memory … ps'.
1690   let pol' ≝ ? in
1691   match status_of_pseudo_status M ps pol with
1692    [ None ⇒ status_of_pseudo_status M ps' pol' = None …
1693    | Some _ ⇒ ∃w. status_of_pseudo_status M ps' pol' = Some … w
1694    ].
1695 [2: <prf @pol]
1696 #M #ps #ps' #pol #H normalize nodelta; whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ])
1697 generalize in match (refl … (assembly (code_memory … ps) pol))
1698 cases (assembly ??) in ⊢ (???% → %)
1699  [ #K whd whd in ⊢ (??%?) <H >K %
1700  | #x #K whd whd in ⊢ (?? (λ_.??%?)) <H >K % [2: % ] ]
1701qed.
1702*)
1703
1704definition ticks_of0: ∀p:pseudo_assembly_program. policy p → (Identifier→Word) → Word → ? → nat × nat ≝
1705  λprogram: pseudo_assembly_program.λpol.λlookup_labels.
1706  λppc: Word.
1707  λfetched.
1708    match fetched with
1709    [ Instruction instr ⇒
1710      match instr with
1711      [ JC lbl ⇒
1712        match pol lookup_labels ppc with
1713        [ short_jump ⇒ 〈2, 2〉
1714        | medium_jump ⇒ ?
1715        | long_jump ⇒ 〈4, 4〉
1716        ]
1717      | JNC lbl ⇒
1718        match pol lookup_labels ppc with
1719        [ short_jump ⇒ 〈2, 2〉
1720        | medium_jump ⇒ ?
1721        | long_jump ⇒ 〈4, 4〉
1722        ]
1723      | JB bit lbl ⇒
1724        match pol lookup_labels ppc with
1725        [ short_jump ⇒ 〈2, 2〉
1726        | medium_jump ⇒ ?
1727        | long_jump ⇒ 〈4, 4〉
1728        ]
1729      | JNB bit lbl ⇒
1730        match pol lookup_labels ppc with
1731        [ short_jump ⇒ 〈2, 2〉
1732        | medium_jump ⇒ ?
1733        | long_jump ⇒ 〈4, 4〉
1734        ]
1735      | JBC bit lbl ⇒
1736        match pol lookup_labels ppc with
1737        [ short_jump ⇒ 〈2, 2〉
1738        | medium_jump ⇒ ?
1739        | long_jump ⇒ 〈4, 4〉
1740        ]
1741      | JZ lbl ⇒
1742        match pol lookup_labels ppc with
1743        [ short_jump ⇒ 〈2, 2〉
1744        | medium_jump ⇒ ?
1745        | long_jump ⇒ 〈4, 4〉
1746        ]
1747      | JNZ lbl ⇒
1748        match pol lookup_labels  ppc with
1749        [ short_jump ⇒ 〈2, 2〉
1750        | medium_jump ⇒ ?
1751        | long_jump ⇒ 〈4, 4〉
1752        ]
1753      | CJNE arg lbl ⇒
1754        match pol lookup_labels ppc with
1755        [ short_jump ⇒ 〈2, 2〉
1756        | medium_jump ⇒ ?
1757        | long_jump ⇒ 〈4, 4〉
1758        ]
1759      | DJNZ arg lbl ⇒
1760        match pol lookup_labels ppc with
1761        [ short_jump ⇒ 〈2, 2〉
1762        | medium_jump ⇒ ?
1763        | long_jump ⇒ 〈4, 4〉
1764        ]
1765      | ADD arg1 arg2 ⇒
1766        let ticks ≝ ticks_of_instruction (ADD ? arg1 arg2) in
1767         〈ticks, ticks〉
1768      | ADDC arg1 arg2 ⇒
1769        let ticks ≝ ticks_of_instruction (ADDC ? arg1 arg2) in
1770         〈ticks, ticks〉
1771      | SUBB arg1 arg2 ⇒
1772        let ticks ≝ ticks_of_instruction (SUBB ? arg1 arg2) in
1773         〈ticks, ticks〉
1774      | INC arg ⇒
1775        let ticks ≝ ticks_of_instruction (INC ? arg) in
1776         〈ticks, ticks〉
1777      | DEC arg ⇒
1778        let ticks ≝ ticks_of_instruction (DEC ? arg) in
1779         〈ticks, ticks〉
1780      | MUL arg1 arg2 ⇒
1781        let ticks ≝ ticks_of_instruction (MUL ? arg1 arg2) in
1782         〈ticks, ticks〉
1783      | DIV arg1 arg2 ⇒
1784        let ticks ≝ ticks_of_instruction (DIV ? arg1 arg2) in
1785         〈ticks, ticks〉
1786      | DA arg ⇒
1787        let ticks ≝ ticks_of_instruction (DA ? arg) in
1788         〈ticks, ticks〉
1789      | ANL arg ⇒
1790        let ticks ≝ ticks_of_instruction (ANL ? arg) in
1791         〈ticks, ticks〉
1792      | ORL arg ⇒
1793        let ticks ≝ ticks_of_instruction (ORL ? arg) in
1794         〈ticks, ticks〉
1795      | XRL arg ⇒
1796        let ticks ≝ ticks_of_instruction (XRL ? arg) in
1797         〈ticks, ticks〉
1798      | CLR arg ⇒
1799        let ticks ≝ ticks_of_instruction (CLR ? arg) in
1800         〈ticks, ticks〉
1801      | CPL arg ⇒
1802        let ticks ≝ ticks_of_instruction (CPL ? arg) in
1803         〈ticks, ticks〉
1804      | RL arg ⇒
1805        let ticks ≝ ticks_of_instruction (RL ? arg) in
1806         〈ticks, ticks〉
1807      | RLC arg ⇒
1808        let ticks ≝ ticks_of_instruction (RLC ? arg) in
1809         〈ticks, ticks〉
1810      | RR arg ⇒
1811        let ticks ≝ ticks_of_instruction (RR ? arg) in
1812         〈ticks, ticks〉
1813      | RRC arg ⇒
1814        let ticks ≝ ticks_of_instruction (RRC ? arg) in
1815         〈ticks, ticks〉
1816      | SWAP arg ⇒
1817        let ticks ≝ ticks_of_instruction (SWAP ? arg) in
1818         〈ticks, ticks〉
1819      | MOV arg ⇒
1820        let ticks ≝ ticks_of_instruction (MOV ? arg) in
1821         〈ticks, ticks〉
1822      | MOVX arg ⇒
1823        let ticks ≝ ticks_of_instruction (MOVX ? arg) in
1824         〈ticks, ticks〉
1825      | SETB arg ⇒
1826        let ticks ≝ ticks_of_instruction (SETB ? arg) in
1827         〈ticks, ticks〉
1828      | PUSH arg ⇒
1829        let ticks ≝ ticks_of_instruction (PUSH ? arg) in
1830         〈ticks, ticks〉
1831      | POP arg ⇒
1832        let ticks ≝ ticks_of_instruction (POP ? arg) in
1833         〈ticks, ticks〉
1834      | XCH arg1 arg2 ⇒
1835        let ticks ≝ ticks_of_instruction (XCH ? arg1 arg2) in
1836         〈ticks, ticks〉
1837      | XCHD arg1 arg2 ⇒
1838        let ticks ≝ ticks_of_instruction (XCHD ? arg1 arg2) in
1839         〈ticks, ticks〉
1840      | RET ⇒
1841        let ticks ≝ ticks_of_instruction (RET ?) in
1842         〈ticks, ticks〉
1843      | RETI ⇒
1844        let ticks ≝ ticks_of_instruction (RETI ?) in
1845         〈ticks, ticks〉
1846      | NOP ⇒
1847        let ticks ≝ ticks_of_instruction (NOP ?) in
1848         〈ticks, ticks〉
1849      ]
1850    | Comment comment ⇒ 〈0, 0〉
1851    | Cost cost ⇒ 〈0, 0〉
1852    | Jmp jmp ⇒ 〈2, 2〉
1853    | Call call ⇒ 〈2, 2〉
1854    | Mov dptr tgt ⇒ 〈2, 2〉
1855    ].
1856  cases not_implemented (* policy returned medium_jump for conditional jumping = impossible *)
1857qed.
1858
1859definition ticks_of: ∀p:pseudo_assembly_program. policy p → (Identifier→Word) → Word → nat × nat ≝
1860  λprogram: pseudo_assembly_program.λpol.λlookup_labels.
1861  λppc: Word.
1862    let 〈preamble, pseudo〉 ≝ program in
1863    let 〈fetched, new_ppc〉 ≝ fetch_pseudo_instruction pseudo ppc in
1864     ticks_of0 program pol lookup_labels ppc fetched.
1865
1866lemma eq_rect_Type1_r:
1867  ∀A: Type[1].
1868  ∀a:A.
1869  ∀P: ∀x:A. eq ? x a → Type[1]. P a (refl A a) → ∀x: A.∀p:eq ? x a. P x p.
1870  #A #a #P #H #x #p
1871  generalize in match H;
1872  generalize in match P;
1873  cases p
1874  //
1875qed.
1876
1877axiom split_append:
1878  ∀A: Type[0].
1879  ∀m, n: nat.
1880  ∀v, v': Vector A m.
1881  ∀q, q': Vector A n.
1882    let 〈v', q'〉 ≝ split A m n (v@@q) in
1883      v = v' ∧ q = q'.
1884
1885axiom split_vector_singleton:
1886  ∀A: Type[0].
1887  ∀n: nat.
1888  ∀v: Vector A (S n).
1889  ∀rest: Vector A n.
1890  ∀s: Vector A 1.
1891  ∀prf.
1892    v = s @@ rest →
1893    ((get_index_v A ? v 0 prf) ::: rest) = v.
1894
1895example sub_minus_one_seven_eight:
1896  ∀v: BitVector 7.
1897  false ::: (\fst (sub_7_with_carry v (bitvector_of_nat ? 1) false)) =
1898  \fst (sub_8_with_carry (false ::: v) (bitvector_of_nat ? 1) false).
1899 cases daemon.
1900qed.
1901
1902(*
1903lemma blah:
1904  ∀m: internal_pseudo_address_map.
1905  ∀s: PseudoStatus.
1906  ∀arg: Byte.
1907  ∀b: bool.
1908    addressing_mode_ok m s (DIRECT arg) = true →
1909      get_arg_8 ? (set_low_internal_ram ? s (low_internal_ram_of_pseudo_low_internal_ram m (low_internal_ram ? s))) b (DIRECT arg) =
1910      get_arg_8 ? s b (DIRECT arg).
1911  [2, 3: normalize % ]
1912  #m #s #arg #b #hyp
1913  whd in ⊢ (??%%)
1914  @split_elim''
1915  #nu' #nl' #arg_nu_nl_eq
1916  normalize nodelta
1917  generalize in match (refl ? (get_index_v bool 4 nu' ? ?))
1918  cases (get_index_v bool 4 nu' ? ?) in ⊢ (??%? → %)
1919  #get_index_v_eq
1920  normalize nodelta
1921  [2:
1922    normalize nodelta
1923    @split_elim''
1924    #bit_one' #three_bits' #bit_one_three_bit_eq
1925    generalize in match (low_internal_ram_of_pseudo_internal_ram_miss m s (three_bits'@@nl'))
1926    normalize nodelta
1927    generalize in match (refl ? (sub_7_with_carry ? ? ?))
1928    cases (sub_7_with_carry ? ? ?) in ⊢ (??%? → %)
1929    #Saddr #carr' #Saddr_carr_eq
1930    normalize nodelta
1931    #carr_hyp'
1932    @carr_hyp'
1933    [1:
1934    |2: whd in hyp:(??%?); generalize in match hyp; -hyp;
1935        generalize in match (refl ? (¬(member (BitVector 8) ? arg m)))
1936        cases (¬(member (BitVector 8) ? arg m)) in ⊢ (??%? → %)
1937        #member_eq
1938        normalize nodelta
1939        [2: #destr destruct(destr)
1940        |1: -carr_hyp';
1941            >arg_nu_nl_eq
1942            <(split_vector_singleton ? ? nu' ? ? ? bit_one_three_bit_eq)
1943            [1: >get_index_v_eq in ⊢ (??%? → ?)
1944            |2: @le_S @le_S @le_S @le_n
1945            ]
1946            cases (member (BitVector 8) ? (\fst ?) ?)
1947            [1: #destr normalize in destr; destruct(destr)
1948            |2:
1949            ]
1950        ]
1951    |3: >get_index_v_eq in ⊢ (??%?)
1952        change in ⊢ (??(???%?)?) with ((? ::: three_bits') @@ nl')
1953        >(split_vector_singleton … bit_one_three_bit_eq)
1954        <arg_nu_nl_eq
1955        whd in hyp:(??%?)
1956        cases (member (BitVector 8) (eq_bv 8) arg m) in hyp
1957        normalize nodelta [*: #ignore @sym_eq ]
1958    ]
1959  |
1960  ].
1961*)
1962(*
1963map_address0 ... (DIRECT arg) = Some .. →
1964  get_arg_8 (map_address0 ... (internal_ram ...) (DIRECT arg) =
1965  get_arg_8 (internal_ram ...) (DIRECT arg)
1966
1967((if addressing_mode_ok M ps ACC_A∧addressing_mode_ok M ps (DIRECT ARG2) 
1968                     then Some internal_pseudo_address_map M 
1969                     else None internal_pseudo_address_map )
1970                    =Some internal_pseudo_address_map M')
1971*)
1972
1973axiom low_internal_ram_write_at_stack_pointer:
1974 ∀T1,T2,M,s1,s2,s3.∀pol.∀pbu,pbl,bu,bl,sp1,sp2:BitVector 8.
1975  get_8051_sfr ? s2 SFR_SP = get_8051_sfr ? s3 SFR_SP →
1976  low_internal_ram ? s2 = low_internal_ram T2 s3 →
1977  sp1 = \snd (half_add ? (get_8051_sfr ? s1 SFR_SP) (bitvector_of_nat 8 1)) →
1978  sp2 = \snd (half_add ? sp1 (bitvector_of_nat 8 1)) →
1979  bu@@bl = sigma (code_memory … s2) pol (pbu@@pbl) →
1980   low_internal_ram T1
1981     (write_at_stack_pointer ?
1982       (set_8051_sfr ?
1983         (write_at_stack_pointer ?
1984           (set_8051_sfr ?
1985             (set_low_internal_ram ? s1
1986               (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram ? s2)))
1987             SFR_SP sp1)
1988          bl)
1989        SFR_SP sp2)
1990      bu)
1991   = low_internal_ram_of_pseudo_low_internal_ram (sp1::M)
1992      (low_internal_ram ?
1993       (write_at_stack_pointer ?
1994         (set_8051_sfr ?
1995           (write_at_stack_pointer ? (set_8051_sfr ? s3 SFR_SP sp1) pbl)
1996          SFR_SP sp2)
1997        pbu)).
1998
1999axiom high_internal_ram_write_at_stack_pointer:
2000 ∀T1,T2,M,s1,s2,s3,pol.∀pbu,pbl,bu,bl,sp1,sp2:BitVector 8.
2001  get_8051_sfr ? s2 SFR_SP = get_8051_sfr ? s3 SFR_SP →
2002  high_internal_ram ? s2 = high_internal_ram T2 s3 →
2003  sp1 = \snd (half_add ? (get_8051_sfr ? s1 SFR_SP) (bitvector_of_nat 8 1)) →
2004  sp2 = \snd (half_add ? sp1 (bitvector_of_nat 8 1)) →
2005  bu@@bl = sigma (code_memory … s2) pol (pbu@@pbl) →
2006   high_internal_ram T1
2007     (write_at_stack_pointer ?
2008       (set_8051_sfr ?
2009         (write_at_stack_pointer ?
2010           (set_8051_sfr ?
2011             (set_high_internal_ram ? s1
2012               (high_internal_ram_of_pseudo_high_internal_ram M (high_internal_ram ? s2)))
2013             SFR_SP sp1)
2014          bl)
2015        SFR_SP sp2)
2016      bu)
2017   = high_internal_ram_of_pseudo_high_internal_ram (sp1::M)
2018      (high_internal_ram ?
2019       (write_at_stack_pointer ?
2020         (set_8051_sfr ?
2021           (write_at_stack_pointer ? (set_8051_sfr ? s3 SFR_SP sp1) pbl)
2022          SFR_SP sp2)
2023        pbu)).
2024
2025lemma Some_Some_elim:
2026 ∀T:Type[0].∀x,y:T.∀P:Type[2]. (x=y → P) → Some T x = Some T y → P.
2027 #T #x #y #P #H #K @H @option_destruct_Some //
2028qed.
2029
2030theorem main_thm:
2031 ∀M,M',ps,pol,lookup_labels.
2032  next_internal_pseudo_address_map M ps = Some … M' →
2033   ∃n.
2034      execute n (status_of_pseudo_status M ps pol)
2035    = status_of_pseudo_status M' (execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol lookup_labels) ps) ?.
2036 [2: >execute_1_pseudo_instruction_preserves_code_memory @pol]
2037 #M #M' #ps #pol #lookup_labels #SAFE
2038 cut
2039  (∀ps'.
2040    ∀prf:ps'=execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol lookup_labels) ps.
2041    ∃n. execute n (status_of_pseudo_status M ps pol) = status_of_pseudo_status M' ps' ?)
2042 [ >prf >execute_1_pseudo_instruction_preserves_code_memory @pol |3: #K @(K ? (refl …))]
2043 #ps' #EQ
2044 whd in ⊢ (??(λ_.??(??%)?));
2045 change with
2046  (∃n.
2047    execute n
2048     (set_low_internal_ram ?
2049       (set_high_internal_ram ?
2050         (set_program_counter ?
2051           (set_code_memory ?? ps (load_code_memory ?))
2052          (sigma ? pol (program_counter ? ps)))
2053        (high_internal_ram_of_pseudo_high_internal_ram M ?))
2054      (low_internal_ram_of_pseudo_low_internal_ram M ?))
2055   = set_low_internal_ram ?
2056      (set_high_internal_ram ?
2057        (set_program_counter ?
2058          (set_code_memory ?? ? (load_code_memory ?))
2059         (sigma ???)) ?) ?);
2060 >EQ whd in match eq_rect_Type0_r; normalize nodelta
2061 >execute_1_pseudo_instruction_preserves_code_memory normalize nodelta
2062 generalize in match EQ; -EQ;
2063 generalize in match (refl … (code_memory pseudo_assembly_program ps));
2064 generalize in match pol; -pol; generalize in ⊢ (∀_.??%? → ?);
2065 * #preamble #instr_list #pol #EQ1 generalize in match pol; -pol <EQ1 #pol #EQps' <EQps'
2066 (* Dependent types madness ends here *)
2067 letin ppc ≝ (program_counter … ps)
2068 generalize in match (fetch_assembly_pseudo2 ? pol ppc) in ⊢ ?;
2069 letin assembled ≝ (\fst (assembly ? pol))
2070 letin lookup_labels ≝ (λx.(address_of_word_labels_code_mem instr_list x))
2071 letin lookup_datalabels ≝ (λx. lookup_def … (construct_datalabels preamble) x (zero 16))
2072 @pair_elim #pi #newppc #EQ2
2073 letin instructions ≝
2074  (expand_pseudo_instruction lookup_labels ppc ((pi1 ?? pol) lookup_labels ppc) lookup_datalabels
2075    pi)
2076 change with (fetch_many ???? → ?); #H1
2077 change with (fetch_pseudo_instruction instr_list ppc = ?) in EQ2;
2078 change with (next_internal_pseudo_address_map0 ???? = ?) in SAFE; <EQ1 in SAFE;
2079 >EQ2 whd in ⊢ (??(??%??)? → ?); #SAFE
2080 whd in EQps':(???%); <EQ1 in EQps'; >EQ2 normalize nodelta
2081 generalize in match H1; -H1; generalize in match instructions; -instructions
2082 * #instructions >EQ2 change with pi in match (\fst 〈pi,newppc〉);
2083 whd in match ticks_of; normalize nodelta <EQ1 >EQ2
2084 cases pi in SAFE;
2085  [2,3: (* Comment, Cost *) #ARG whd in ⊢ (??%? → ???% → ?);
2086   @Some_Some_elim #MAP #EQ3 @(Some_Some_elim ????? EQ3) #EQ3'
2087   whd in match eject normalize nodelta >EQ3' in ⊢ (% → ?) whd in ⊢ (% → ?)
2088   #H2 #EQ %[1,3:@0]
2089   <MAP >(eq_bv_eq … H2) >EQ %
2090  |4: (* Jmp *) #label whd in ⊢ (??%? → ???% → ?)
2091   @Some_Some_elim #MAP cases (pol ?) normalize nodelta
2092       [3: (* long *) #EQ3 @(Some_Some_elim ????? EQ3) #EQ3'
2093         whd in match eject normalize nodelta >EQ3' in ⊢ (% → ?) whd in ⊢ (% → ?)
2094         @pair_elim' * #instr #newppc' #ticks #EQ4       
2095         * * #H2a #H2b whd in ⊢ (% → ?) #H2
2096         >H2b >(eq_instruction_to_eq … H2a)
2097         #EQ %[@1]
2098         <MAP >(eq_bv_eq … H2) >EQ
2099         whd in ⊢ (??%?) >EQ4 whd in ⊢ (??%?)
2100         cases ps in EQ4; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXX >XXX %
2101         whd in ⊢ (??%?)
2102         whd in ⊢ (??(match ?%? with [_ ⇒ ?])?)
2103         cases ps in EQ0 ⊢ %; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXXX >XXXX %
2104  |6: (* Mov *) #arg1 #arg2
2105       #H1 #H2 #EQ %[@1]
2106       normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2107       change in ⊢ (? → ??%?) with (execute_1_0 ??)
2108       cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2109       * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2110       >H2b >(eq_instruction_to_eq … H2a)
2111       generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?);
2112       @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1; whd in ⊢ (???% → ??%?)
2113       @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2; #ARG2
2114       normalize nodelta;
2115       [1,2,3,4,5,6,7,8: cases (add_8_with_carry ???) |*: cases (sub_8_with_carry ???)]
2116       #result #flags
2117       #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) %
2118  |5: (* Call *) #label #MAP
2119      generalize in match (option_destruct_Some ??? MAP) -MAP; #MAP <MAP -MAP;
2120      whd in ⊢ (???% → ?) cases (pol ?) normalize nodelta;
2121       [ (* short *) #abs @⊥ destruct (abs)
2122       |3: (* long *) #H1 #H2 #EQ %[@1]
2123           (* normalize in H1; !!!*) generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2124           change in ⊢ (? → ??%?) with (execute_1_0 ??)
2125           cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2126           * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2127           >H2b >(eq_instruction_to_eq … H2a)
2128           generalize in match EQ; -EQ;
2129           whd in ⊢ (???% → ??%?);
2130           generalize in match (refl … (half_add 8 (get_8051_sfr ? ps SFR_SP) (bitvector_of_nat ? 1))) cases (half_add ???) in ⊢ (??%? → %) #carry #new_sp #EQ1 normalize nodelta;
2131           >(eq_bv_eq … H2c)
2132           change with
2133            ((?=let 〈ppc_bu,ppc_bl〉 ≝ split bool 8 8 newppc in ?) →
2134                (let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc) in ?)=?)
2135           generalize in match (refl … (split … 8 8 newppc)) cases (split bool 8 8 newppc) in ⊢ (??%? → %) #ppc_bu #ppc_bl #EQppc
2136           generalize in match (refl … (split … 8 8 (sigma 〈preamble,instr_list〉 pol newppc))) cases (split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc)) in ⊢ (??%? → %) #pc_bu #pc_bl #EQpc normalize nodelta;
2137           >get_8051_sfr_write_at_stack_pointer >get_8051_sfr_write_at_stack_pointer
2138           >get_8051_sfr_set_8051_sfr >get_8051_sfr_set_8051_sfr
2139           generalize in match (refl … (half_add ? new_sp (bitvector_of_nat ? 1))) cases (half_add ???) in ⊢ (??%? → %) #carry' #new_sp' #EQ2 normalize nodelta;
2140           #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c)
2141           @split_eq_status;
2142            [ >code_memory_write_at_stack_pointer whd in ⊢ (??%?)
2143              >code_memory_write_at_stack_pointer %
2144            | >set_program_counter_set_low_internal_ram
2145              >set_clock_set_low_internal_ram
2146              @low_internal_ram_write_at_stack_pointer
2147               [ >EQ0 @pol | % | %
2148               | @(pair_destruct_2 … EQ1)
2149               | @(pair_destruct_2 … EQ2)
2150               | >(pair_destruct_1 ????? EQpc)
2151                 >(pair_destruct_2 ????? EQpc)
2152                 @split_elim #x #y #H <H -x y H;
2153                 >(pair_destruct_1 ????? EQppc)
2154                 >(pair_destruct_2 ????? EQppc)
2155                 @split_elim #x #y #H <H -x y H;
2156                 >EQ0 % ]
2157            | >set_low_internal_ram_set_high_internal_ram
2158              >set_program_counter_set_high_internal_ram
2159              >set_clock_set_high_internal_ram
2160              @high_internal_ram_write_at_stack_pointer
2161               [ >EQ0 @pol | % | %
2162               | @(pair_destruct_2 … EQ1)
2163               | @(pair_destruct_2 … EQ2)
2164               | >(pair_destruct_1 ????? EQpc)
2165                 >(pair_destruct_2 ????? EQpc)
2166                 @split_elim #x #y #H <H -x y H;
2167                 >(pair_destruct_1 ????? EQppc)
2168                 >(pair_destruct_2 ????? EQppc)
2169                 @split_elim #x #y #H <H -x y H;
2170                 >EQ0 % ]           
2171            | >external_ram_write_at_stack_pointer whd in ⊢ (??%?)
2172              >external_ram_write_at_stack_pointer whd in ⊢ (???%)
2173              >external_ram_write_at_stack_pointer whd in ⊢ (???%)
2174              >external_ram_write_at_stack_pointer %
2175            | change with (? = sigma ?? (address_of_word_labels_code_mem (\snd (code_memory ? ps)) ?))
2176              >EQ0 %
2177            | >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (??%?)
2178              >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (???%)
2179              >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (???%)
2180              >special_function_registers_8051_write_at_stack_pointer %
2181            | >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (??%?)
2182              >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (???%)
2183              >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (???%)
2184              >special_function_registers_8052_write_at_stack_pointer %
2185            | >p1_latch_write_at_stack_pointer whd in ⊢ (??%?)
2186              >p1_latch_write_at_stack_pointer whd in ⊢ (???%)
2187              >p1_latch_write_at_stack_pointer whd in ⊢ (???%)
2188              >p1_latch_write_at_stack_pointer %
2189            | >p3_latch_write_at_stack_pointer whd in ⊢ (??%?)
2190              >p3_latch_write_at_stack_pointer whd in ⊢ (???%)
2191              >p3_latch_write_at_stack_pointer whd in ⊢ (???%)
2192              >p3_latch_write_at_stack_pointer %
2193            | >clock_write_at_stack_pointer whd in ⊢ (??%?)
2194              >clock_write_at_stack_pointer whd in ⊢ (???%)
2195              >clock_write_at_stack_pointer whd in ⊢ (???%)
2196              >clock_write_at_stack_pointer %]
2197       (*| (* medium *)  #H1 #H2 #EQ %[@1] generalize in match H1; -H1;
2198         @pair_elim' #fst_5_addr #rest_addr #EQ1
2199         @pair_elim' #fst_5_pc #rest_pc #EQ2
2200         generalize in match (refl … (eq_bv … fst_5_addr fst_5_pc))
2201         cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta; #EQ3 #TEQ [2: destruct (TEQ)]
2202         generalize in match (option_destruct_Some ??? TEQ) -TEQ; #K1 >K1 in H2; whd in ⊢ (% → ?)
2203         change in ⊢ (? →??%?) with (execute_1_0 ??)
2204         @pair_elim' * #instr #newppc' #ticks #EQn
2205          * * #H2a #H2b whd in ⊢ (% → ?) #H2c >H2b >(eq_instruction_to_eq … H2a) whd in ⊢ (??%?)
2206          generalize in match EQ; -EQ; normalize nodelta; >(eq_bv_eq … H2c)
2207          @pair_elim' #carry #new_sp change with (half_add ? (get_8051_sfr ? ps ?) ? = ? → ?) #EQ4
2208          @split_elim' #pc_bu #pc_bl >program_counter_set_8051_sfr XXX change with (newppc = ?) #EQ5
2209          @pair_elim' #carry' #new_sp' #EQ6 normalize nodelta; #EQx >EQx -EQx;
2210          change in ⊢ (??(match ????% with [_ ⇒ ?])?) with (sigma … newppc)
2211          @split_elim' #pc_bu' #pc_bl' #EQ7 change with (newppc' = ? → ?)
2212          >get_8051_sfr_set_8051_sfr
2213         
2214          whd in EQ:(???%) ⊢ ? >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) whd in ⊢ (??%?)
2215           change with ((let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 newppc) in ?)=?)
2216           generalize in match (refl … (split bool 8 8 (sigma 〈preamble,instr_list〉 newppc)))
2217           cases (split ????) in ⊢ (??%? → %) #pc_bu #pc_bl normalize nodelta; #EQ4
2218           generalize in match (refl … (split bool 4 4 pc_bu))
2219           cases (split ????) in ⊢ (??%? → %) #nu #nl normalize nodelta; #EQ5
2220           generalize in match (refl … (split bool 3 8 rest_addr))
2221           cases (split ????) in ⊢ (??%? → %) #relevant1 #relevant2 normalize nodelta; #EQ6
2222           change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma … newppc) ? in ?) = ?)
2223           generalize in match
2224            (refl …
2225             (half_add 16 (sigma 〈preamble,instr_list〉 newppc)
2226             ((nu@@get_index' bool 0 3 nl:::relevant1)@@relevant2)))
2227           cases (half_add ???) in ⊢ (??%? → %) #carry #new_pc normalize nodelta; #EQ7
2228           @split_eq_status try %
2229            [ change with (? = sigma ? (address_of_word_labels ps label))
2230              (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *)
2231            | whd in ⊢ (??%%) whd in ⊢ (??(?%?)?) whd in ⊢ (??(?(match ?(?%)? with [_ ⇒ ?])?)?)
2232              @(bitvector_3_elim_prop … (\fst (split bool 3 8 rest_addr))) %]] *)]
2233  |4: (* Jmp *) #label #MAP
2234      generalize in match (option_destruct_Some ??? MAP) -MAP; #MAP >MAP -MAP;
2235      whd in ⊢ (???% → ?) cases (pol ?) normalize nodelta;
2236       [3: (* long *) #H1 #H2 #EQ %[@1]
2237           (* normalize in H1; !!!*) generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2238           change in ⊢ (? → ??%?) with (execute_1_0 ??)
2239           cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2240           * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2241           >H2b >(eq_instruction_to_eq … H2a)
2242           generalize in match EQ; -EQ;
2243           #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c)
2244           cases ps in EQ0 ⊢ %; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXXX >XXXX %
2245       |1: (* short *) #H1 #H2 #EQ %[@1] generalize in match H1; -H1;
2246           generalize in match
2247            (refl ?
2248             (sub_16_with_carry
2249              (sigma 〈preamble,instr_list〉 pol (program_counter … ps))
2250              (sigma 〈preamble,instr_list〉 pol (address_of_word_labels_code_mem instr_list label))
2251              false))
2252           cases (sub_16_with_carry ???) in ⊢ (??%? → %); #results #flags normalize nodelta;
2253           generalize in match (refl … (split … 8 8 results)) cases (split ????) in ⊢ (??%? → %) #upper #lower normalize nodelta;
2254           generalize in match (refl … (eq_bv … upper (zero 8))) cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta;
2255           #EQ1 #EQ2 #EQ3 #H1 [2: @⊥ destruct (H1)]
2256           generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2257           change in ⊢ (? → ??%?) with (execute_1_0 ??)
2258           cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2259           * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2260           >H2b >(eq_instruction_to_eq … H2a)
2261           generalize in match EQ; -EQ;
2262           whd in ⊢ (???% → ?);
2263           #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c)
2264           change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma ???) ? in ?) = ?)
2265           generalize in match (refl … (half_add 16 (sigma 〈preamble,instr_list〉 pol newppc) (sign_extension lower)))
2266           cases (half_add ???) in ⊢ (??%? → %) #carry #newpc normalize nodelta #EQ4
2267           @split_eq_status try % change with (newpc = sigma ?? (address_of_word_labels ps label))
2268           (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *)
2269       | (* medium *)  #H1 #H2 #EQ %[@1] generalize in match H1; -H1;
2270         generalize in match
2271          (refl …
2272            (split … 5 11 (sigma 〈preamble,instr_list〉 pol (address_of_word_labels_code_mem instr_list label))))
2273         cases (split ????) in ⊢ (??%? → %) #fst_5_addr #rest_addr normalize nodelta; #EQ1
2274         generalize in match
2275          (refl …
2276            (split … 5 11 (sigma 〈preamble,instr_list〉 pol (program_counter … ps))))
2277         cases (split ????) in ⊢ (??%? → %) #fst_5_pc #rest_pc normalize nodelta; #EQ2
2278         generalize in match (refl … (eq_bv … fst_5_addr fst_5_pc))
2279         cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta; #EQ3 #TEQ [2: destruct (TEQ)]
2280         generalize in match (option_destruct_Some ??? TEQ) -TEQ; #K1 >K1 in H2; whd in ⊢ (% → ?)
2281         change in ⊢ (? →??%?) with (execute_1_0 ??)
2282           cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2283           * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2284           >H2b >(eq_instruction_to_eq … H2a)
2285           generalize in match EQ; -EQ;
2286           whd in ⊢ (???% → ?);
2287           #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) whd in ⊢ (??%?)
2288           change with ((let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc) in ?)=?)
2289           generalize in match (refl … (split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc)))
2290           cases (split ????) in ⊢ (??%? → %) #pc_bu #pc_bl normalize nodelta; #EQ4
2291           generalize in match (refl … (split bool 4 4 pc_bu))
2292           cases (split ????) in ⊢ (??%? → %) #nu #nl normalize nodelta; #EQ5
2293           generalize in match (refl … (split bool 3 8 rest_addr))
2294           cases (split ????) in ⊢ (??%? → %) #relevant1 #relevant2 normalize nodelta; #EQ6
2295           change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma … newppc) ? in ?) = ?)
2296           generalize in match
2297            (refl …
2298             (half_add 16 (sigma 〈preamble,instr_list〉 pol newppc)
2299             ((nu@@get_index' bool 0 3 nl:::relevant1)@@relevant2)))
2300           cases (half_add ???) in ⊢ (??%? → %) #carry #new_pc normalize nodelta; #EQ7   
2301           @split_eq_status try %
2302            [ change with (? = sigma ?? (address_of_word_labels ps label))
2303              (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *)
2304            | whd in ⊢ (??%%) whd in ⊢ (??(?%?)?) whd in ⊢ (??(?(match ?(?%)? with [_ ⇒ ?])?)?)
2305              @(bitvector_3_elim_prop … (\fst (split bool 3 8 rest_addr))) %]]
2306  | (* Instruction *) -pi;  whd in ⊢ (? → ??%? → ?) *; normalize nodelta;
2307    [1,2,3: (* ADD, ADDC, SUBB *) #arg1 #arg2 #MAP #H1 #H2 #EQ %[1,3,5:@1]
2308       normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2309       change in ⊢ (? → ??%?) with (execute_1_0 ??)
2310       cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2311       * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2312       >H2b >(eq_instruction_to_eq … H2a)
2313       generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?); generalize in match MAP; -MAP;
2314       @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1;
2315       @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2; #ARG2
2316       normalize nodelta; #MAP;
2317       [1: change in ⊢ (? → %) with
2318        ((let 〈result,flags〉 ≝
2319          add_8_with_carry
2320           (get_arg_8 ? ps false ACC_A)
2321           (get_arg_8 ?
2322             (set_low_internal_ram ? ps (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps)))
2323             false (DIRECT ARG2))
2324           ? in ?) = ?)
2325        [2,3: %]
2326        change in ⊢ (???% → ?) with
2327         (let 〈result,flags〉 ≝ add_8_with_carry ?(*(get_arg_8 ? ps false ACC_A)*) ?? in ?)
2328        >get_arg_8_set_clock
2329       [1,2: cases (addressing_mode_ok ???? ∧ addressing_mode_ok ????) in MAP ⊢ ?
2330         [2,4: #abs @⊥ normalize in abs; destruct (abs)
2331         |*:whd in ⊢ (??%? → ?) #H <(option_destruct_Some ??? H)]
2332       [ change in ⊢ (? → %) with
2333        ((let 〈result,flags〉 ≝
2334          add_8_with_carry
2335           (get_arg_8 ? ps false ACC_A)
2336           (get_arg_8 ?
2337             (set_low_internal_ram ? ps (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps)))
2338             false (DIRECT ARG2))
2339           ? in ?) = ?)
2340          >get_arg_8_set_low_internal_ram
2341       
2342        cases (add_8_with_carry ???)
2343         
2344        [1,2,3,4,5,6,7,8: cases (add_8_with_carry ???) |*: cases (sub_8_with_carry ???)]
2345       #result #flags
2346       #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) %
2347    | (* INC *) #arg1 #H1 #H2 #EQ %[@1]
2348       normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?)
2349       change in ⊢ (? → ??%?) with (execute_1_0 ??)
2350       cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta;
2351       * * #H2a #H2b whd in ⊢ (% → ?) #H2c
2352       >H2b >(eq_instruction_to_eq … H2a)
2353       generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?);
2354       @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1; normalize nodelta; [1,2,3: #ARG]
2355       [1,2,3,4: cases (half_add ???) #carry #result
2356       | cases (half_add ???) #carry #bl normalize nodelta;
2357         cases (full_add ????) #carry' #bu normalize nodelta ]
2358        #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) -newppc';
2359        [5: %
2360        |1: <(set_arg_8_set_code_memory 0 [[direct]] ? ? ? (set_clock pseudo_assembly_program
2361      (set_program_counter pseudo_assembly_program ps newppc)
2362      (\fst  (ticks_of0 〈preamble,instr_list〉
2363                   (program_counter pseudo_assembly_program ps)
2364                   (Instruction (INC Identifier (DIRECT ARG))))
2365       +clock pseudo_assembly_program
2366        (set_program_counter pseudo_assembly_program ps newppc))) (load_code_memory assembled) result (DIRECT ARG))
2367        [2,3: // ]
2368            <(set_arg_8_set_program_counter 0 [[direct]] ? ? ? ? ?) [2://]
2369            whd in ⊢ (??%%)
2370            cases (split bool 4 4 ARG)
2371            #nu' #nl'
2372            normalize nodelta
2373            cases (split bool 1 3 nu')
2374            #bit_1' #ignore'
2375            normalize nodelta
2376            cases (get_index_v bool 4 nu' ? ?)
2377            [ normalize nodelta (* HERE *) whd in ⊢ (??%%) %
2378            |
2379            ]
2380cases daemon (* EASY CASES TO BE COMPLETED *)
2381qed.
Note: See TracBrowser for help on using the repository browser.