]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/contribs/ng_assembly/freescale/byte8.ma
freescale porting, work in progress
[helm.git] / helm / software / matita / contribs / ng_assembly / freescale / byte8.ma
index ca59bc5b76fefb33ae6c9a2272b462026dcec063..f15537cc75f6a1c5dd6eb5905c94d7c7eaad0be7 100755 (executable)
@@ -21,6 +21,7 @@
 (* ********************************************************************** *)
 
 include "freescale/exadecim.ma".
+include "freescale/bitrigesim.ma".
 
 (* **** *)
 (* BYTE *)
@@ -90,10 +91,10 @@ ndefinition ror_b8 ≝
    | false ⇒ mk_byte8 bh' bl' ]]].
 
 (* operatore rotazione destra n-volte *)
-nlet rec ror_b8_n (b:byte8) (n:nat) on n ≝
- match n with
-  [ O ⇒ b
-  | S n' ⇒ ror_b8_n (ror_b8 b) n' ].
+nlet rec ror_b8_n (b:byte8) (n:oct) (r:rec_oct n) on r ≝
+ match r with
+  [ oc_O ⇒ b
+  | oc_S t n' ⇒ ror_b8_n (ror_b8 b) t n' ].
 
 (* operatore rotazione sinistra con carry *)
 ndefinition rcl_b8 ≝
@@ -116,10 +117,10 @@ ndefinition rol_b8 ≝
    | false ⇒ mk_byte8 bh' bl' ]]].
 
 (* operatore rotazione sinistra n-volte *)
-nlet rec rol_b8_n (b:byte8) (n:nat) on n ≝
- match n with
-  [ O ⇒ b
-  | S n' ⇒ rol_b8_n (rol_b8 b) n' ].
+nlet rec rol_b8_n (b:byte8) (n:oct) (r:rec_oct n) on r ≝
+ match r with
+  [ oc_O ⇒ b
+  | oc_S t n' ⇒ rol_b8_n (rol_b8 b) t n' ].
 
 (* operatore not/complemento a 1 *)
 ndefinition not_b8 ≝
@@ -164,9 +165,6 @@ ndefinition plus_b8_d_c ≝
 (* operatore Most Significant Bit *)
 ndefinition MSB_b8 ≝ λb:byte8.eq_ex x8 (and_ex x8 (b8h b)).
 
-(* byte → naturali *)
-ndefinition nat_of_byte8 ≝ λb:byte8.(16*(nat_of_exadecim (b8h b))) + (nat_of_exadecim (b8l b)).
-
 (* operatore predecessore *)
 ndefinition pred_b8 ≝
 λb:byte8.match eq_ex (b8l b) x0 with
@@ -302,8 +300,64 @@ ndefinition daa_b8 ≝
   ].
 
 (* iteratore sui byte *)
-ndefinition forall_byte8 ≝
+ndefinition forall_b8 ≝
  λP.
-  forall_exadecim (λbh.
-  forall_exadecim (λbl.
+  forall_ex (λbh.
+  forall_ex (λbl.
    P (mk_byte8 bh bl))).
+
+(* byte ricorsivi *)
+ninductive rec_byte8 : byte8 → Type ≝
+  b8_O : rec_byte8 〈x0,x0〉
+| b8_S : ∀n.rec_byte8 n → rec_byte8 (succ_b8 n).
+
+(* byte → byte ricorsivi *)
+ndefinition b8_to_recb8_aux1 : Πn.rec_byte8 〈n,x0〉 → rec_byte8 〈succ_ex n,x0〉 ≝
+λn.λrecb:rec_byte8 〈n,x0〉.
+ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (
+ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))))).
+
+(* ... cifra esadecimale superiore *)
+nlet rec b8_to_recb8_aux2 (n:exadecim) (r:rec_exadecim n) on r ≝
+ match r return λx.λy:rec_exadecim x.rec_byte8 〈x,x0〉 with
+  [ ex_O ⇒ b8_O
+  | ex_S t n' ⇒ b8_to_recb8_aux1 ? (b8_to_recb8_aux2 t n')
+  ].
+
+(* ... cifra esadecimale inferiore *)
+ndefinition b8_to_recb8_aux3 : Πn1,n2.rec_byte8 〈n1,x0〉 → rec_byte8 〈n1,n2〉 ≝
+λn1,n2.λrecb:rec_byte8 〈n1,x0〉.
+ match n2 return λx.rec_byte8 〈n1,x〉 with
+  [ x0 ⇒ recb
+  | x1 ⇒ b8_S ? recb
+  | x2 ⇒ b8_S ? (b8_S ? recb)
+  | x3 ⇒ b8_S ? (b8_S ? (b8_S ? recb))
+  | x4 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))
+  | x5 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))
+  | x6 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))
+  | x7 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))
+  | x8 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))
+  | x9 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))
+  | xA ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))
+  | xB ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))
+  | xC ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))))
+  | xD ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))
+  | xE ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))))))
+  | xF ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))))
+  ].
+
+ndefinition b8_to_recb8 ≝
+λn.b8_to_recb8_aux3 (b8h n) (b8l n) (b8_to_recb8_aux2 (b8h n) (ex_to_recex (b8h n))).
+
+(* ottali → esadecimali *)
+ndefinition b8_of_bit ≝
+λn.match n with
+ [ t00 ⇒ 〈x0,x0〉 | t01 ⇒ 〈x0,x1〉 | t02 ⇒ 〈x0,x2〉 | t03 ⇒ 〈x0,x3〉
+ | t04 ⇒ 〈x0,x4〉 | t05 ⇒ 〈x0,x5〉 | t06 ⇒ 〈x0,x6〉 | t07 ⇒ 〈x0,x7〉
+ | t08 ⇒ 〈x0,x8〉 | t09 ⇒ 〈x0,x9〉 | t0A ⇒ 〈x0,xA〉 | t0B ⇒ 〈x0,xB〉
+ | t0C ⇒ 〈x0,xC〉 | t0D ⇒ 〈x0,xD〉 | t0E ⇒ 〈x0,xE〉 | t0F ⇒ 〈x0,xF〉
+ | t10 ⇒ 〈x1,x0〉 | t11 ⇒ 〈x1,x1〉 | t12 ⇒ 〈x1,x2〉 | t13 ⇒ 〈x1,x3〉
+ | t14 ⇒ 〈x1,x4〉 | t15 ⇒ 〈x1,x5〉 | t16 ⇒ 〈x1,x6〉 | t17 ⇒ 〈x1,x7〉
+ | t18 ⇒ 〈x1,x8〉 | t19 ⇒ 〈x1,x9〉 | t1A ⇒ 〈x1,xA〉 | t1B ⇒ 〈x1,xB〉
+ | t1C ⇒ 〈x1,xC〉 | t1D ⇒ 〈x1,xD〉 | t1E ⇒ 〈x1,xE〉 | t1F ⇒ 〈x1,xF〉
+ ].