completed phase 1?
This commit is contained in:
parent
0332001ef8
commit
bc78a83838
11 changed files with 306 additions and 44 deletions
43
ass2/SICocaml/test.ml
Normal file
43
ass2/SICocaml/test.ml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(* 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 ()
|
||||
Loading…
Add table
Add a link
Reference in a new issue