SPO_JakaFurlan/ass2/SICocaml/test.ml
2025-11-29 20:28:00 +01:00

43 lines
1.2 KiB
OCaml

(* test_execute.ml *)
open Processor (* assuming your state, regs, and execute are defined here *)
(* Helper to write 3-byte instruction to memory *)
let write_instruction3 state addr byte1 byte2 byte3 =
Bytes.set state.memory addr (Char.chr byte1);
Bytes.set state.memory (addr+1) (Char.chr byte2);
Bytes.set state.memory (addr+2) (Char.chr byte3)
(* 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 = 4; 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 ()