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

Last change on this file since 90 was 90, checked in by mulligan, 10 years ago

Ported physical.ml to be compatible with new bitvector code, started
porting ASMInterpret.

File size: 1.3 KB
RevLine 
[90]1open BitVectors;;
[88]2
[44]3exception Byte7_conversion
[28]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)
[44]13  | _ -> raise Byte7_conversion
[28]14
15let add8_with_c b1 b2 c =
[90]16 let n1 = int_of_vect b1 in
17 let n2 = int_of_vect b2 in
18 let c = int_of_vect c in
[28]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
[90]24   vect_of_int res,c,ac,ov
[28]25;;
26
27let subb8_with_c b1 b2 c =
[90]28 let n1 = int_of_vect b1 in
29 let n2 = int_of_vect b2 in
30 let c = int_of_vect c in
[28]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
[90]38  (vect_of_int res `Eight,c,ac,ov)
[28]39;;
40
41let dec b =
[90]42 let res = int_of_vect b - 1 in
43  if res < 0 then vect_of_int 255 `Eight
44  else vect_of_int res `Eight
[28]45;;
46
47let inc b =
[90]48 let res = int_of_vect b + 1 in
49  if res > 255 then vect_of_int 0 `Eight
50  else vect_of_int res `Eight
[28]51;;
[41]52
[42]53let byte7_of_bit b =
54  false,false,false,(false,false,false,b)
[41]55;;
[42]56
57let byte_of_byte7 (b1,b2,b3,n) =
58        (false,b1,b2,b3),n
[88]59;;
Note: See TracBrowser for help on using the repository browser.