Changeset 86


Ignore:
Timestamp:
Sep 17, 2010, 5:12:19 PM (9 years ago)
Author:
mulligan
Message:

Adding bit vector file.

Location:
Deliverables/D4.1
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/ASMInstruction.ml

    r84 r86  
    242242  let to_string =
    243243    function
    244       ACALL (`ADDR11 (a10,a9,a8,b1)) ->
    245       "ACALL addr11 (" ^ Word11.to_string (a10,a9,a8,b1) ^ ")"
     244      ACALL (`ADDR11 w) ->
     245      "ACALL addr11 (" ^ Word11.to_string w ^ ")"
    246246    | ADD (`A,`REG (r1,r2,r3)) ->
    247247     "ADD A Rn (" ^ Bit.to_string r1 ^ Bit.to_string r2 ^ Bit.to_string r3 ^ ")"
     
    260260    | ADDC (`A,`DATA b1) ->
    261261     "ADDC A #data (" ^ Byte.to_string b1 ^ ")"
    262     | AJMP (`ADDR11 (a10,a9,a8,b1)) ->
    263      "AJMP addr11 (" ^ Word11.to_string (a10,a9,a8,b1) ^ ")"
     262    | AJMP (`ADDR11 w) ->
     263     "AJMP addr11 (" ^ Word11.to_string w ^ ")"
    264264    | ANL (`U1 (`A, `REG (r1,r2,r3))) ->
    265265     "ANL A Rn (" ^ Bit.to_string r1 ^ Bit.to_string r2 ^ Bit.to_string r3 ^ ")"
     
    334334    | JZ (`REL b1) ->
    335335    "JZ rel (" ^ Byte.to_string b1 ^ ")"
    336     | LCALL (`ADDR16 (b1,b2)) ->
    337     "LCALL addr16 (" ^ Byte.to_string b1 ^ Byte.to_string b2 ^ ")"
    338     | LJMP (`ADDR16 (b1,b2)) ->
    339     "LJMP addr16 (" ^ Byte.to_string b1 ^ Byte.to_string b2 ^ ")"
     336    | LCALL (`ADDR16 w) ->
     337    "LCALL addr16 (" ^ Word.to_string w ^ ")"
     338    | LJMP (`ADDR16 w) ->
     339    "LJMP addr16 (" ^ Word.to_string w ^ ")"
    340340    | MOV (`U1 (`A, `REG(r1,r2,r3))) ->
    341341    "MOV A Rn (" ^ Bit.to_string r1 ^ Bit.to_string r2 ^ Bit.to_string r3 ^ ")"
     
    372372    | MOV (`U6 (`BIT b1, `C)) ->
    373373    "MOV bit C (" ^ Byte.to_string b1 ^ ")"
    374     | MOV (`U4 (`DPTR, `DATA16(b1,b2))) ->
    375     "MOV DPTR #data16 (" ^ Byte.to_string b1 ^ Byte.to_string b2 ^ ")"
     374    | MOV (`U4 (`DPTR, `DATA16 w)) ->
     375    "MOV DPTR #data16 (" ^ Word.to_string w ^ ")"
    376376    | MOVC (`A, `A_DPTR) ->
    377377    "MOVC A @A + DPTR"
  • Deliverables/D4.1/Byte.ml

    r85 r86  
    2323
    2424  val to_bit: byte -> bit option
     25  val to_bits: byte -> bit list
    2526  val to_nibble: byte -> nibble option
    2627  val to_int: byte -> int
     
    128129      else
    129130        None
     131  let to_bits (n1, n2) = Nibble.to_bits n1 @ Nibble.to_bits n2
    130132  let to_nibble (n1, n2) =
    131133    let (b1, b2, b3, b4) = Nibble.to_bits n1 in
     
    135137      else None
    136138  let to_int (n1, n2) =
    137     let (b1, b2, b3, b4) = Nibble.to_bits n1 in
    138     let (b5, b6, b7, b8) = Nibble.to_bits n2 in
     139    let [b1; b2; b3; b4] = Nibble.to_bits n1 in
     140    let [b5; b6; b7; b8] = Nibble.to_bits n2 in
    139141      (128 * Bit.to_int b8) + (64 * Bit.to_int b8) +
    140142      (32 * Bit.to_int b8) + (16 * Bit.to_int b8) +
  • Deliverables/D4.1/Byte7.ml

    r85 r86  
    1414  type bit
    1515  type nibble
    16   type byte7
     16  type byte7 = private (bit * bit * bit * nibble)
     17
     18  val get_bit_at: int -> byte7 -> bit option
     19  val set_bit_at: int -> bit -> byte7 -> byte7 option
     20
     21  val (-&-): byte7 -> byte7 -> byte7
     22  val (-|-): byte7 -> byte7 -> byte7
     23  val (-^-): byte7 -> byte7 -> byte7
     24  val not: byte7 -> byte7
     25
     26  val iter_bit: (bit -> string) -> byte7 -> string
     27  val map_bit: (bit -> bit) -> byte7 -> byte7
     28  val zip_bit: (bit -> bit -> bit) -> byte7 -> byte7 -> byte7
     29  val to_string: byte7 -> string
    1730end;;
    1831
    1932module Byte7Functor(Bit: BIT)
    2033                   (Nibble: NIBBLE
    21                       with type bit = Bit.bit) : BYTE7
     34                      with type bit = Bit.bit): BYTE7
    2235  with type bit    = Bit.bit
    2336  and  type nibble = Nibble.nibble =
     
    2538  type bit = Bit.bit
    2639  type nibble = Nibble.nibble
    27   type byte7 = private (bit * bit * bit * nibble)
     40  type byte7 = bit * bit * bit * nibble
     41
     42  let get_bit_at index (b1,b2,b3,b) =
     43    if index < 4 then
     44      Nibble.get_bit_at index b
     45    else
     46      match index with
     47        4 -> Some b3
     48      | 5 -> Some b2
     49      | 6 -> Some b1
     50      | _ -> None
     51  let set_bit_at index new_val (b1,b2,b3,b) =
     52    if index < 4 then
     53      let nib = Nibble.set_bit_at index new_val b in
     54        match nib with
     55          Some nib -> Some (b1, b2, b3, nib)
     56        | None -> None
     57    else
     58      match index with
     59        4 -> Some (b3, b2, new_val, b)
     60      | 5 -> Some (b3, new_val, b1, b)
     61      | 6 -> Some (new_val, b2, b1, b)
     62      | _ -> None
     63
     64  let (-&-) (l1, l2, l3, l) (r1, r2, r3, r) =
     65    (Bit.(-&-) l1 r1, Bit.(-&-) l2 r2, Bit.(-&-) l3 r3, Nibble.(-&-) l r)
     66  let (-|-) (l1, l2, l3, l) (r1, r2, r3, r) =
     67    (Bit.(-|-) l1 r1, Bit.(-|-) l2 r2, Bit.(-|-) l3 r3, Nibble.(-|-) l r)
     68  let (-^-) (l1, l2, l3, l) (r1, r2, r3, r) =
     69    (Bit.(-^-) l1 r1, Bit.(-^-) l2 r2, Bit.(-^-) l3 r3, Nibble.(-^-) l r)
     70  let not (b1, b2, b3, b) = (Bit.not b1, Bit.not b2, Bit.not b3, Nibble.not b)
     71
     72  let iter_bit f (b1, b2, b3, b) =
     73    let n_bits = f b1 ^ f b2 ^ f b3 in
     74    let n_byte = Nibble.iter_bit f b in
     75      n_bits ^ n_byte
     76  let map_bit f (b1, b2, b3, b) =
     77    (f b1, f b2, f b3, Nibble.map_bit f b)
     78  let zip_bit f (l1, l2, l3, l) (r1, r2, r3, r) =
     79    (f l1 r1, f l2 r2, f l3 r3, Nibble.zip_bit f l r)
     80
     81  let to_string = iter_bit Bit.to_string
    2882end;;
    2983
  • Deliverables/D4.1/Nibble.ml

    r85 r86  
    1919  (* val from_string: string -> nibble option *)
    2020
    21   val to_bits: nibble -> (bit * bit * bit * bit)
     21  val to_bits: nibble -> bit list
    2222  val to_bit: nibble -> bit option
    2323  val to_int: nibble -> int
     
    7979      (false, false, false, b) -> Some (Bit.from_bool b)
    8080   |  _ -> None
    81   let to_bits (b1, b2, b3, b4) = (b1, b2, b3, b4)
     81  let to_bits (b1, b2, b3, b4) = [b1; b2; b3; b4]
    8282  let to_int (b1, b2, b3, b4) = (8 * Bit.to_int b1) + (4 * Bit.to_int b2) +
    8383                                (2 * Bit.to_int b3) + Bit.to_int b4
  • Deliverables/D4.1/SFR.ml

    r83 r86  
    1717  type sfr
    1818
    19   val empty: sfr
     19  val power_on: sfr
    2020
    2121  val get_p0: sfr -> byte
  • Deliverables/D4.1/Word.ml

    r85 r86  
    1717  type byte
    1818  type word = private byte * byte
     19
     20  val to_bits: word -> bit list
     21
     22  val iter_bit: (bit -> string) -> word -> string
     23
     24  val to_string: word -> string
    1925end;;
    2026
     
    3339  type byte = Byte.byte
    3440  type word = (byte * byte)
     41
     42  let to_bits (b1, b2) = Byte.to_bits b1 @ Byte.to_bits b2
     43
     44  let iter_bit f w = foldr (^) "" (map f (to_bits w))
     45
     46  let to_string = iter_bit Bit.to_string
    3547end;;
    3648
  • Deliverables/D4.1/Word11.ml

    r85 r86  
    1616  type word11 = private (bit * bit * bit * byte)
    1717
     18  val get_bit_at: int -> word11 -> bit option
     19  val set_bit_at: int -> bit -> word11 -> word11 option
     20
     21  val (-&-): word11 -> word11 -> word11
     22  val (-|-): word11 -> word11 -> word11
     23  val (-^-): word11 -> word11 -> word11
     24(*
     25  val rotate_right: word11 -> word11
     26  val rotate_left: word11 -> word11
     27  val shift_right: word11 -> word11
     28  val shift_left: word11 -> word11
     29*)
     30  val not: word11 -> word11
     31
     32  val map_bit: (bit -> bit) -> word11 -> word11
     33  val iter_bit: (bit -> string) -> word11 -> string
     34  val zip_bit: (bit -> bit -> bit) -> word11 -> word11 -> word11
     35
     36  val zero: word11
     37
     38  val half_add: word11 -> word11 -> (word11 * bit)
     39  val full_add: (word11 * bit) -> word11 -> (word11 * bit)
     40
    1841  val to_string: word11 -> string
    1942end;;
     
    2952  type word11 = bit * bit * bit * byte
    3053
    31   let to_string (b1,b2,b3,b) =
    32     Bit.to_string b1 ^ Bit.to_string b2 ^ Bit.to_string b3 ^ Byte.to_string b
     54  let get_bit_at index (b1,b2,b3,b) =
     55    if index < 8 then
     56      Byte.get_bit_at index b
     57    else
     58      match index with
     59        8 -> Some b3
     60      | 9 -> Some b2
     61      | 10 -> Some b1
     62      | _ -> None
     63  let set_bit_at index new_val (b1,b2,b3,b) =
     64    if index < 8 then
     65      let nib = Byte.set_bit_at index new_val b in
     66        match nib with
     67          Some nib -> Some (b1, b2, b3, nib)
     68        | None -> None
     69    else
     70      match index with
     71        8 -> Some (b3, b2, new_val, b)
     72      | 9 -> Some (b3, new_val, b1, b)
     73      | 10 -> Some (new_val, b2, b1, b)
     74      | _ -> None
     75
     76  let (-&-) (l1, l2, l3, l) (r1, r2, r3, r) =
     77    (Bit.(-&-) l1 r1, Bit.(-&-) l2 r2, Bit.(-&-) l3 r3, Byte.(-&-) l r)
     78  let (-|-) (l1, l2, l3, l) (r1, r2, r3, r) =
     79    (Bit.(-|-) l1 r1, Bit.(-|-) l2 r2, Bit.(-|-) l3 r3, Byte.(-|-) l r)
     80  let (-^-) (l1, l2, l3, l) (r1, r2, r3, r) =
     81    (Bit.(-^-) l1 r1, Bit.(-^-) l2 r2, Bit.(-^-) l3 r3, Byte.(-^-) l r)
     82  let not (b1, b2, b3, b) = (Bit.not b1, Bit.not b2, Bit.not b3, Byte.not b)
     83
     84  let map_bit f (b1, b2, b3, b) =
     85    (f b1, f b2, f b3, Byte.map_bit f b)
     86  let iter_bit f (b1, b2, b3, b) =
     87    let n_bits = f b1 ^ f b2 ^ f b3 in
     88    let n_byte = Byte.iter_bit f b in
     89      n_bits ^ n_byte
     90  let zip_bit f (l1, l2, l3, l) (r1, r2, r3, r) =
     91    (f l1 r1, f l2 r2, f l3 r3, Byte.zip_bit f l r)
     92
     93  let zero = (Bit.zero, Bit.zero, Bit.zero, Byte.zero)
     94
     95  let to_string = iter_bit Bit.to_string
     96
     97  let half_add (l1, l2, l3, l) (r1, r2, r3, r) =
     98    let (n, c) = Byte.half_add l r in
     99    let (n3, c3) = Bit.full_add (l3, c) r3 in
     100    let (n2, c2) = Bit.full_add (l2, c3) r2 in
     101    let (n1, c1) = Bit.full_add (l1, c2) r1 in
     102      ((n1, n2, n3, n), c1)
     103  let full_add ((l1, l2, l3, l), c) (r1, r2, r3, r) =
     104    let (n, c) = Byte.full_add (l, c) r in
     105    let (n3, c3) = Bit.full_add (l3, c) r3 in
     106    let (n2, c2) = Bit.full_add (l2, c3) r2 in
     107    let (n1, c1) = Bit.full_add (l1, c2) r1 in
     108      ((n1, n2, n3, n), c1) 
     109  let to_string = iter_bit Bit.to_string
    33110end;;
    34111
Note: See TracChangeset for help on using the changeset viewer.