source: Deliverables/D4.1/test.ml @ 194

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

Manages to load and emulate a simple array program. A few obscure bugs.

File size: 1.0 KB
RevLine 
[147]1open BitVectors;;
2open Util;;
3open Pretty;;
4
[145]5let hex = IntelHex.intel_hex_of_file "Test.hex" in
[138]6let mem = IntelHex.process_intel_hex hex in
7let status = ASMInterpret.load_mem mem ASMInterpret.initialize in
8let observe status =
9 let pc = status.ASMInterpret.pc in
10 let instr,_,_ = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
[145]11   prerr_string (BitVectors.hex_string_of_vect pc) ;
[147]12   prerr_endline (": " ^ pp_instruction instr)
[138]13in
[147]14(* DPM: for debugging! *)
15let mem_pretty_print status =
16  let rec aux status pc =
17    let instr, pc', cost = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
18      prerr_string $ ((hex_string_of_vect pc) ^ ": ");
19      prerr_string $ (pp_instruction instr) ^ " ";
20      prerr_endline $ string_of_int cost;
[150]21      if int_of_vect pc' > 200 then (* DPM: hardcoded on a case-by-case basis *)
[147]22        ()
23      else
24        aux status pc'
25  in
26    aux status status.ASMInterpret.pc;
27    prerr_endline "-------------------------------------"
28in
[150]29 mem_pretty_print status;
[138]30 ASMInterpret.execute observe status
31;;
Note: See TracBrowser for help on using the repository browser.