37 lines
931 B
OCaml
37 lines
931 B
OCaml
(* test_execute.ml *)
|
|
|
|
open Processor (* assuming your state, regs, and execute are defined here *)
|
|
|
|
(* Test function *)
|
|
let test_execute () =
|
|
(* Create a dummy state *)
|
|
let mem_size = 1024 in
|
|
let memory = Bytes.make mem_size '\000' in
|
|
let regs = {
|
|
a = 0; b = 0; x = 0; l = 0; s = 0; t = 0; f = 0.0;
|
|
pc = 0; sw = 0
|
|
} in
|
|
let state = { memory; regs } in
|
|
|
|
(* Example: Write a LDA instruction at address 0*)
|
|
Processor.write_instruction3 state 0 '\x01' '\x00' '\x23';
|
|
|
|
(* Write the operand value at 0x010 *)
|
|
Processor.writeMemAddr state 0x010 0x123456;
|
|
|
|
(* Set PC to 0 *)
|
|
state.regs.pc <- 0;
|
|
|
|
Printf.printf "Before execution:\n";
|
|
Processor.print_regs state;
|
|
Processor.print_memory state 15;
|
|
|
|
(* Execute instruction *)
|
|
Izvajalnik.execute state;
|
|
|
|
Printf.printf "After execution:\n";
|
|
Processor.print_regs state;
|
|
Processor.print_memory state 15
|
|
|
|
(* Run the test *)
|
|
let () = test_execute ()
|