Changeset 62


Ignore:
Timestamp:
Sep 10, 2010, 5:37:19 PM (8 years ago)
Author:
mulligan
Message:

Many additions to Bit, Nibble and Byte API, as well as more instructions
added to ASMInterpret execute function.

Location:
Deliverables/D4.1
Files:
4 edited

Legend:

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

    r60 r62  
    812812     let ag_val = fetch_arg1 status (`BIT b) in
    813813       set_arg1 status (not ag_val) (`BIT b)
    814 (*
    815  | CPL of [ acc | carry | bit ]
    816 *)
    817814 | RL `A ->
    818815     let (b1,b2,b3,b4),(b5,b6,b7,b8) = status.acc in
  • Deliverables/D4.1/Bit.ml

    r57 r62  
     1(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     2(* FILENAME: Bit.ml                                                          *)
     3(* DESCRIPTION: An ADT implementing bits, and common operations on them.     *)
     4(* CREATED: 10/09/2010, Dominic Mulligan                                     *)
     5(* BUGS:                                                                     *)
     6(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     7
    18module type BIT =
    29sig
  • Deliverables/D4.1/Byte.ml

    r57 r62  
     1(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     2(* FILENAME: Byte.ml                                                         *)
     3(* DESCRIPTION: An ADT implementing bytes, and common operations on them.    *)
     4(* CREATED: 10/09/2010, Dominic Mulligan                                     *)
     5(* BUGS:                                                                     *)
     6(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     7
     8open Bit;;
    19open Nibble;;
    210
    3 module type BYTE = functor(Nibble: NIBBLE) ->
     11module type BYTE =
    412sig
    5   type nibble = Nibble.nibble
     13  type bit
     14  type nibble
     15  type byte
     16(*
     17  val from_bits: bit -> bit -> bit -> bit -> bit -> bit -> bit -> bit -> byte
     18  val from_nibbles: nibble -> nibble -> byte
     19  val from_int: int -> byte
     20
     21  val get_nibble_at: int -> byte -> nibble
     22  val set_nibble_at: int -> nibble -> byte -> byte option
     23  val get_bit_at: int -> byte -> bit
     24  val set_bit_at: int -> bit -> byte -> byte option
     25
     26  val (-&-): byte -> byte -> byte
     27  val (-|-): byte -> byte -> byte
     28  val (-^-): byte -> byte -> byte
     29  val not: byte -> byte
     30
     31  val map_nibble: (nibble -> nibble) -> byte -> byte
     32  val map_bit: (bit -> bit) -> byte -> byte
     33  val iter_nibble: (nibble -> string) -> byte -> string
     34  val iter_bit: (bit -> string) -> byte -> string
     35  val zip_nibble: (nibble -> nibble -> nibble) -> byte -> byte -> byte
     36  val zip_bit: (bit -> bit -> bit) -> byte -> byte -> byte
     37  val pretty: byte -> string
     38*)
    639end
    740
    8 module Byte: BYTE = functor(Nibble: NIBBLE) ->
     41module Byte(Nibble: NIBBLE): BYTE
     42  with type bit = Nibble.bit and type nibble = Nibble.nibble =
    943struct
     44  type bit = Nibble.bit
    1045  type nibble = Nibble.nibble
     46  type byte = nibble * nibble
    1147end
  • Deliverables/D4.1/Nibble.ml

    r57 r62  
     1(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     2(* FILENAME: Nibble.ml                                                       *)
     3(* DESCRIPTION: An ADT implementing nibbles, and common operations on them.  *)
     4(* CREATED: 10/09/2010, Dominic Mulligan                                     *)
     5(* BUGS:                                                                     *)
     6(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     7
    18open Bit;;
    29
    3 module type NIBBLE = functor(Bit: BIT) ->
     10module type NIBBLE =
    411sig
    5   type bit = Bit.bit
     12  type bit
    613  type nibble
    714
    815  val from_bits: bit -> bit -> nibble
     16  val from_int: int -> nibble option
    917
    10   val upper_bit: nibble -> bit
    11   val lower_bit: nibble -> bit
     18  val get_bit_at: int -> nibble -> bit option
     19  val set_bit_at: int -> bit -> nibble -> nibble option
    1220
    1321  val (-&-): nibble -> nibble -> nibble
     
    1624  val not: nibble -> nibble
    1725
    18   val swap: nibble -> nibble
     26  val swap_bits: nibble -> nibble
    1927
    20   val mask: (bit -> bit) -> nibble -> nibble
    21   val zip: (bit -> bit -> bit) -> nibble -> nibble -> nibble
     28  val map_bit: (bit -> bit) -> nibble -> nibble
     29  val iter_bit: (bit -> string) -> nibble -> string
     30  val zip_bit: (bit -> bit -> bit) -> nibble -> nibble -> nibble
     31  val pretty: nibble -> string
    2232end
    2333
    24 module NibbleFunctor: NIBBLE = functor(Bit: BIT) ->
     34module NibbleFunctor(Bit: BIT) : NIBBLE with type bit = Bit.bit =
    2535struct
    2636  type bit = Bit.bit
     
    2838
    2939  let from_bits l h = (l, h)
     40  let from_int int_val =
     41    match int_val with
     42      0 -> Some (Bit.from_int 0, Bit.from_int 0)
     43    | 1 -> Some (Bit.from_int 0, Bit.from_int 1)
     44    | 2 -> Some (Bit.from_int 1, Bit.from_int 0)
     45    | 3 -> Some (Bit.from_int 1, Bit.from_int 1)
     46    | _ -> None
    3047
    31   let upper_bit (l, r) = r
    32   let lower_bit (l, r) = l
     48  let get_bit_at index (l, h) =
     49    if index = 0 then
     50      Some l
     51    else if index = 1 then
     52      Some h
     53    else
     54      None
     55
     56  let set_bit_at index new_bit (l, h) =
     57    if index = 0 then
     58      Some (new_bit, h)
     59    else if index = 1 then
     60      Some (l, new_bit)
     61    else
     62      None
    3363
    3464  let (-&-) (l1,h1) (l2, h2) =
     
    4171  let not (l, h) = (Bit.not l, Bit.not h)
    4272
    43   let swap (l, h) = (h, l)
     73  let swap_bits (l, h) = (h, l)
    4474
    45   let mask f (l, h) = (f l, f h)
    46   let zip f (l1, h1) (l2, h2) = (f l1 l2, f l2 h2)
     75  let map_bit f (l, h) = (f l, f h)
     76  let iter_bit f (l, h) =
     77    let str_l = f l in
     78    let str_h = f h in
     79      str_l ^ str_h
     80  let zip_bit f (l1, h1) (l2, h2) = (f l1 l2, f l2 h2)
     81  let pretty = iter_bit Bit.pretty
    4782end
     83
     84module Nibble = NibbleFunctor(Bit)
Note: See TracChangeset for help on using the changeset viewer.