-(*
- operatore moltiplicazione senza segno: b*b=[0x0000,0xFE01]
- ... in pratica (〈a,b〉*〈c,d〉) = (a*c)<<8+(a*d)<<4+(b*c)<<4+(b*d)
-*)
-ndefinition mul_b8 ≝
-λb1,b2:byte8.match b1 with
-[ mk_byte8 b1h b1l ⇒ match b2 with
-[ mk_byte8 b2h b2l ⇒ match mul_ex b1l b2l with
-[ mk_byte8 t1_h t1_l ⇒ match mul_ex b1h b2l with
-[ mk_byte8 t2_h t2_l ⇒ match mul_ex b2h b1l with
-[ mk_byte8 t3_h t3_l ⇒ match mul_ex b1h b2h with
-[ mk_byte8 t4_h t4_l ⇒
- plus_w16_d_d
- (plus_w16_d_d
- (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈t1_h,t1_l〉〉
-]]]]]].
-
-(* divisione senza segno (secondo la logica delle ALU): (quoziente resto) overflow *)
-nlet rec div_b8_aux (divd:word16) (divs:word16) (molt:byte8) (q:byte8) (c:nat) on c ≝
- let w' ≝ plus_w16_d_d divd (compl_w16 divs) in
- match c with
- [ O ⇒ match le_w16 divs divd with
- [ true ⇒ triple … (or_b8 molt q) (w16l w') (⊖ (eq_b8 (w16h w') 〈x0,x0〉))
- | false ⇒ triple … q (w16l divd) (⊖ (eq_b8 (w16h divd) 〈x0,x0〉)) ]
- | S c' ⇒ match le_w16 divs divd with
- [ true ⇒ div_b8_aux w' (ror_w16 divs) (ror_b8 molt) (or_b8 molt q) c'
- | false ⇒ div_b8_aux divd (ror_w16 divs) (ror_b8 molt) q c' ]].
-
-ndefinition div_b8 ≝
-λw:word16.λb:byte8.match eq_b8 b 〈x0,x0〉 with
-(*
- la combinazione n/0 e' illegale, segnala solo overflow senza dare risultato
-*)
- [ true ⇒ triple … 〈xF,xF〉 (w16l w) true
- | false ⇒ match eq_w16 w 〈〈x0,x0〉:〈x0,x0〉〉 with
-(* 0 diviso qualsiasi cosa diverso da 0 da' q=0 r=0 o=false *)
- [ true ⇒ triple … 〈x0,x0〉 〈x0,x0〉 false
-(* 1) e' una divisione sensata che produrra' overflow/risultato *)
-(* 2) parametri: dividendo, divisore, moltiplicatore, quoziente, contatore *)
-(* 3) ad ogni ciclo il divisore e il moltiplicatore vengono scalati di 1 a dx *)
-(* 4) il moltiplicatore e' la quantita' aggiunta al quoziente se il divisore *)
-(* puo' essere sottratto al dividendo *)
- | false ⇒ div_b8_aux w (rol_w16_n 〈〈x0,x0〉:b〉 nat7) 〈x8,x0〉 〈x0,x0〉 nat7 ]].
-