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

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

Fixed physical interface file. Refactoring ASMInterface.

File size: 1.6 KB
Line 
1open BitVectors;;
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 int_of_bit =
11  function
12    false -> 0
13  | true -> 1
14
15let byte7_of_byte b =
16  let bits = to_bits b in
17    match bits with
18      [false;b1;b2;b3;b4;b5;b6;b7] -> mk_byte7 b1 b2 b3 (mk_nibble b4 b5 b6 b7)
19    | _ -> raise Byte7_conversion
20
21let add8_with_c (b1 : [`Eight] vect) (b2 : [`Eight] vect) (c : bit) =
22 let n1 = int_of_vect b1 in
23 let n2 = int_of_vect b2 in
24 let c = int_of_bit c in
25 let res = n1 + n2 + c in
26 let ac = n1 mod 16 + n2 mod 16 + c >= 16 in
27 let c6 = n1 mod 128 + n2 mod 128 + c >= 128 in
28 let res,c = res mod 256, res >= 256 in
29 let ov = c <> c6 in
30   vect_of_int res `Eight,c,ac,ov
31;;
32
33let subb8_with_c (b1 : [`Eight] vect) (b2 : [`Eight] vect) (c : bit) =
34 let n1 = int_of_vect b1 in
35 let n2 = int_of_vect b2 in
36 let c = int_of_bit c in
37 let res = n1 - n2 - c in
38 let ac = n1 mod 16 - n2 mod 16 - c < 0 in
39 let c6 = n1 mod 128 - n2 mod 128 - c < 0 in
40 let res,c =
41  if res >= 0 then res,false
42  else n1 + 256 - n2 - c, true in
43 let ov = c <> c6 in
44  (vect_of_int res `Eight,c,ac,ov)
45;;
46
47let dec b =
48 let res = int_of_vect b - 1 in
49  if res < 0 then vect_of_int 255 `Eight
50  else vect_of_int res `Eight
51;;
52
53let inc b =
54 let res = int_of_vect b + 1 in
55  if res > 255 then (vect_of_int 0 `Eight : byte)
56  else (vect_of_int res `Eight : byte)
57;;
58
59let byte7_of_bit b =
60  [false;false;false;false;false;false;b]
61;;
62
63let byte_of_byte7 ([b1;b2;b3]::n) =
64        [false;b1;b2;b3]::n
65;;
Note: See TracBrowser for help on using the repository browser.