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

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

Added more info to status printout. Found weird bug in emulator: cjne
is sometimes interpreted as a jnz instruction.

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