Changeset 83
 Timestamp:
 Sep 16, 2010, 3:31:33 PM (10 years ago)
 Location:
 Deliverables/D4.1
 Files:

 1 added
 6 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D4.1/8051Series.ml
r67 r83 13 13 type word 14 14 15 type sfr 16 17 type code_memory 18 type low_internal_ram 19 type high_internal_ram 20 type external_ram 21 15 22 type processor_status 16 23 type program_counter … … 21 28 22 29 val power_up: processor_status 23 val next: program_counter > processor_status >24 30 end;; 31 32 module 8051_Series (Bit: BIT) 33 (Nibble: NIBBLE 34 with type bit = Bit.bit) 35 (Byte: BYTE 36 with type bit = Bit.bit 37 and type nibble = Nibble.nibble) 38 (Byte7: BYTE7 39 with type bit = Bit.bit 40 and type nibble = Nibble.nibble) 41 (Word: WORD 42 with type bit = Bit.bit 43 and type nibble = Nibble.nibble 44 and type byte = Byte.byte) 45 (SpecialFunctionRegister: SFR 46 with type bit = Bit.bit 47 and type byte = Byte.byte): 8051_SERIES = 48 struct 49 type bit = Bit.bit 50 type nibble = Nibble.nibble 51 type byte = Byte.byte 52 type byte7 = Byte.byte7 53 type word = Word.word 54 55 type sfr = SpecialFunctionRegister.sfr 56 57 type code_memory = word Map.Make (struct type t = byte7 let compare = Pervasives.compare end) 58 type low_internal_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end) 59 type high_internal_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end) 60 type external_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end) 61 62 type processor_status = { 63 program_counter: word; 64 sfr: sfr; 65 66 } 67 end;; 
Deliverables/D4.1/ASMInterpret.ml
r81 r83 739 739 else true 740 740 ;; 741 742 let power_on = 743 status 744 { 745 code_memory = WordMap.empty; 746 external_memory = WordMap.empty; 747 low_internal_ram = Byte7Map.empty; 748 high_internal_ram = Byte7Map.empty; 749 750 pc = 751 } 752 ;; 753 741 754 742 755 let execute1 status = 
Deliverables/D4.1/Bit.ml
r64 r83 22 22 val (^): bit > bit > bit 23 23 val not: bit > bit 24 25 val zero: bit 26 27 (* Half add: two input bits, returns addition of bit plus carry. *) 28 val half_add: bit > bit > (bit * bit) 29 (* Full add: two input bits, plus input carry bit, returns *) 30 (* addition of input bits plus carry. *) 31 val full_add: (bit * bit) > bit > (bit * bit) 24 32 end;; 25 33 … … 67 75 true > false 68 76  false > true 77 78 let zero = false 79 80 let half_add l r = (l ^ r, l & r) 81 let full_add (l, c) r = 82 ((l ^ r) ^ c, (l & r)  (c & (l ^ r))) 69 83 end;; 
Deliverables/D4.1/Byte.ml
r67 r83 4 4 (* operations on them. *) 5 5 (* CREATED: 10/09/2010, Dominic Mulligan *) 6 (* BUGS: 6 (* BUGS: `from_int' not yet implemented. *) 7 7 (*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*) 8 8 … … 20 20 val from_nibbles: nibble > nibble > byte 21 21 val from_nibble: nibble > byte 22 (* 23 val from_int: int > byte 24 *) 22 (* val from_int: int > byte *) 23 25 24 val to_bit: byte > bit option 26 25 val to_nibble: byte > nibble option … … 48 47 val zip_bit: (bit > bit > bit) > byte > byte > byte 49 48 val to_string: byte > string 49 50 val zero: byte 51 val half_add: byte > byte > (byte * bit) 52 val full_add: (byte * bit) > byte > (byte * bit) 50 53 end 51 54 … … 74 77 (Bit.from_bool false) (Bit.from_bool false) in 75 78 (n1, n2) 79 (* let from_int = assert false DPM: finish! *) 76 80 77 81 let get_nibble_at index (n1, n2) = … … 197 201 (new_n1, new_n2) 198 202 let to_string = iter_nibble Nibble.to_string 203 204 let zero = (Nibble.zero, Nibble.zero) 205 let half_add (l1, l2) (r1, r2) = 206 let (a2, c2) = Nibble.half_add l2 r2 in 207 let (a1, c1) = Nibble.full_add (l1, c2) r2 in 208 ((a1, a2), c1) 209 let full_add ((l1, l2), c) (r1, r2) = 210 let (a2, c2) = Nibble.full_add (l2, c) r2 in 211 let (a1, c1) = Nibble.full_add (l1, c2) r2 in 212 ((a1, a2), c1) 199 213 end;; 200 214 
Deliverables/D4.1/Nibble.ml
r66 r83 39 39 val iter_bit: (bit > string) > nibble > string 40 40 val zip_bit: (bit > bit > bit) > nibble > nibble > nibble 41 42 val zero: nibble 43 44 val half_add: nibble > nibble > (nibble * bit) 45 val full_add: (nibble * bit) > nibble > (nibble * bit) 41 46 end 42 47 … … 116 121 117 122 let to_string = iter_bit Bit.to_string 118 end119 123 120 module Nibble = NibbleFunctor(Bit) 124 let zero = (Bit.zero, Bit.zero, Bit.zero, Bit.zero) 125 let half_add (l1, l2, l3, l4) (r1, r2, r3, r4) = 126 let (a4, c4) = Bit.half_add l4 r4 in 127 let (a3, c3) = Bit.full_add (l3, c4) r3 in 128 let (a2, c2) = Bit.full_add (l2, c3) r2 in 129 let (a1, c1) = Bit.full_add (l1, c2) r1 in 130 ((a1, a2, a3, a4), c1) 131 let full_add ((l1, l2, l3, l4), c) (r1, r2, r3, r4) = 132 let (a4, c4) = Bit.full_add (l4, c) r4 in 133 let (a3, c3) = Bit.full_add (l3, c4) r3 in 134 let (a2, c2) = Bit.full_add (l2, c3) r2 in 135 let (a1, c1) = Bit.full_add (l1, c2) r1 in 136 ((a1, a2, a3, a4), c1) 137 end;; 138 139 module Nibble = NibbleFunctor(Bit);; 
Deliverables/D4.1/Word.ml
r67 r83 1 1 (*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*) 2 (* FILENAME: Byte.ml *)3 (* DESCRIPTION: An ADT implementing standard 8 bit bytes, and common*)2 (* FILENAME: Word.ml *) 3 (* DESCRIPTION: An ADT implementing standard 16 bit words, and common *) 4 4 (* operations on them. *) 5 5 (* CREATED: 13/09/2010, Dominic Mulligan *)
Note: See TracChangeset
for help on using the changeset viewer.