source: Deliverables/D4.1/physical.ml @ 88

Last change on this file since 88 was 88, checked in by mulligan, 9 years ago

int_of_vect implemented.

File size: 1.3 KB
Line 
1open Bit_vectors
2
3exception Byte7_conversion
4
5module Byte7Map =
6  Map.Make (struct type t = byte7 let compare = Pervasives.compare end)
7module WordMap =
8  Map.Make (struct type t = word let compare = Pervasives.compare end)
9
10let byte7_of_byte =
11 function
12    (false,b2,b3,b4),n -> (b2,b3,b4,n)
13  | _ -> raise Byte7_conversion
14
15let add8_with_c b1 b2 c =
16 let n1 = int_of_byte b1 in
17 let n2 = int_of_byte b2 in
18 let c = int_of_bit c in
19 let res = n1 + n2 + c in
20 let ac = n1 mod 16 + n2 mod 16 + c >= 16 in
21 let c6 = n1 mod 128 + n2 mod 128 + c >= 128 in
22 let res,c = res mod 256, res >= 256 in
23 let ov = c <> c6 in
24  byte_of_int res,c,ac,ov
25;;
26
27let subb8_with_c b1 b2 c =
28 let n1 = int_of_byte b1 in
29 let n2 = int_of_byte b2 in
30 let c = int_of_bit c in
31 let res = n1 - n2 - c in
32 let ac = n1 mod 16 - n2 mod 16 - c < 0 in
33 let c6 = n1 mod 128 - n2 mod 128 - c < 0 in
34 let res,c =
35  if res >= 0 then res,false
36  else n1 + 256 - n2 - c, true in
37 let ov = c <> c6 in
38  byte_of_int res,c,ac,ov
39;;
40
41let dec b =
42 let res = int_of_byte b - 1 in
43  if res < 0 then byte_of_int 255
44  else byte_of_int res
45;;
46
47let inc b =
48 let res = int_of_byte b + 1 in
49  if res > 255 then byte_of_int 0
50  else byte_of_int res
51;;
52
53let byte7_of_bit b =
54  false,false,false,(false,false,false,b)
55;;
56
57let byte_of_byte7 (b1,b2,b3,n) =
58        (false,b1,b2,b3),n
59;;
Note: See TracBrowser for help on using the repository browser.