Changeset 88 for Deliverables/D4.1/physical.ml
 Timestamp:
 Sep 20, 2010, 10:35:53 AM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D4.1/physical.ml
r58 r88 1 open Bit_vectors 2 1 3 exception Byte7_conversion 2 3 type bit = bool4 type nibble = bit * bit * bit * bit5 type byte = nibble * nibble6 type byte7 = bit * bit * bit * nibble7 type word = byte * byte8 type word11 = bit * bit * bit * byte9 4 10 5 module Byte7Map = … … 17 12 (false,b2,b3,b4),n > (b2,b3,b4,n) 18 13  _ > raise Byte7_conversion 19 20 let int_of_bit b = if b then 0 else 121 22 let int_of_nibble (b1,b2,b3,b4) =23 int_of_bit b4 + int_of_bit b3 * 2 + int_of_bit b2 * 4 + int_of_bit b1 * 824 25 let int_of_byte (n1,n2) = int_of_nibble n2 + int_of_nibble n1 * 1626 27 let int_of_byte7 (b1,b2,b3,n2) = int_of_nibble n2 + int_of_bit b3 * 16 +28 int_of_bit b2 * 32 + int_of_bit b1 * 6429 30 let int_of_word (b1,b2) = int_of_byte b2 + int_of_byte b1 * 25631 32 let bit_of_int n =33 if n >= 2 then assert false34 else35 if n = 0 then false36 else true37 ;;38 39 let nibble_of_int n =40 if n >= 16 then assert false41 else42 let b1 = n / 8 in43 let b2 = (n mod 8) / 4 in44 let b3 = (n mod 4) / 2 in45 let b4 = n mod 2 in46 bit_of_int b1, bit_of_int b2, bit_of_int b3, bit_of_int b447 ;;48 49 let byte_of_int n =50 if n >= 256 then assert false51 else52 let b1 = n / 16 in53 let b2 = n mod 16 in54 nibble_of_int b1, nibble_of_int b255 ;;56 57 let byte7_of_int n =58 if n >= 128 then assert false59 else60 let (_,b1,b2,b3),n = byte_of_int n in61 (b1,b2,b3,n)62 ;;63 64 let word_of_int n =65 if n >= 256 * 256 then assert false66 else67 let b1 = n / 256 in68 let b2 = n mod 256 in69 byte_of_int b1, byte_of_int b270 ;;71 72 let complement ((b1,b2,b3,b4),(b5,b6,b7,b8)) =73 (not b1,not b2,not b3,not b4),(not b5,not b6,not b7,not b8)74 75 let (++) w n = word_of_int (int_of_word w + n);;76 14 77 15 let add8_with_c b1 b2 c = … … 119 57 let byte_of_byte7 (b1,b2,b3,n) = 120 58 (false,b1,b2,b3),n 121 122 let nth_bit pos ((b1,b2,b3,b4),(b5,b6,b7,b8)) = 123 match pos with 124 0 > b1 125  1 > b2 126  2 > b3 127  3 > b4 128  4 > b5 129  5 > b6 130  6 > b7 131  7 > b8 132 133 let set_nth_bit pos v ((b1,b2,b3,b4) as n1,((b5,b6,b7,b8) as n2)) = 134 match pos with 135 0 > ((v,b2,b3,b4),n2) 136  1 > ((b1,v,b3,b4),n2) 137  2 > ((b1,b2,v,b4),n2) 138  3 > ((b1,b2,b3,v),n2) 139  4 > (n1,(v,b6,b7,b8)) 140  5 > (n1,(b5,v,b7,b8)) 141  6 > (n1,(b5,b6,v,b8)) 142  7 > (n1,(b5,b6,b7,v)) 59 ;;
Note: See TracChangeset
for help on using the changeset viewer.