fixed ass2

This commit is contained in:
Jaka Furlan 2025-12-08 12:08:50 +01:00
parent c707e3253c
commit 1bbc80de29
37 changed files with 753 additions and 18 deletions

View file

@ -9,7 +9,7 @@ let state = Processor.{regs; memory}
let test_runner () =
let khz = 0.001 in
Processor.print_memory state 80;
Loader.load_object_file state "/mnt/c/Programiranje/SPO/ass1/arithr.obj";
Loader.load_object_file state "/mnt/c/Programiranje/SPO/ass1/fact.obj";
Processor.print_memory state 80;
Printf.printf "\n\n---Starting execution!---\n\n";
Pogajalnik.run state khz

View file

@ -85,7 +85,7 @@ let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int
(*pridobi operand*)
let value =
if nixbpe.n = 1 && nixbpe.i = 1 then Processor.readMemAddr state ea (*direktno*)
else if nixbpe.n = 0 && nixbpe.i = 1 then disp (* immediate value *)
else if nixbpe.n = 0 && nixbpe.i = 1 then ea (* immediate value *)
else if nixbpe.n = 1 && nixbpe.i = 0 then Processor.readMemAddr state (Processor.readMemAddr state ea) (* indirect *)
else failwith "Invalid addressing mode"
in
@ -102,7 +102,7 @@ let getOperandF4 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int
(*pridobi operand*)
let value =
if nixbpe.n = 1 && nixbpe.i = 1 then Processor.readMemAddr state ea (*direktno*)
else if nixbpe.n = 0 && nixbpe.i = 1 then disp (* immediate value *)
else if nixbpe.n = 0 && nixbpe.i = 1 then ea (* immediate value *)
else if nixbpe.n = 1 && nixbpe.i = 0 then Processor.readMemAddr state (Processor.readMemAddr state ea) (* indirect *)
else failwith "Invalid addressing mode"
in
@ -191,9 +191,9 @@ let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
| LDT -> IzvajalnikF3.ldt state operand
| LDX -> IzvajalnikF3.ldx state operand
| LPS -> notImplemented "LPS4"
| STA -> IzvajalnikF3.sta state operand
| STB -> IzvajalnikF3.stb state operand
| STCH -> IzvajalnikF3.stch state operand
| STA -> IzvajalnikF3.sta state ea
| STB -> IzvajalnikF3.stb state ea
| STCH -> IzvajalnikF3.stch state ea
| STF -> notImplemented "STF4"
| STL -> IzvajalnikF3.stl state ea
| STS -> IzvajalnikF3.sts state ea
@ -208,7 +208,7 @@ let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
let executeFormat4 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit =
let address = readAddress state in
let _, operand = getOperandF4 state nixbpe address in
let ea, operand = getOperandF4 state nixbpe address in
(*debugging*)
Printf.printf "[Izvajalnik/executeFormat4] Mnemonic: %s, nixbpe: %s, operand: %d = 0x%02X\n"
(string_of_mnemonic mnemonic) (string_of_nixbpe nixbpe) operand operand;
@ -246,15 +246,15 @@ let executeFormat4 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
| LDT -> IzvajalnikF4.ldt state operand
| LDX -> IzvajalnikF4.ldx state operand
| LPS -> notImplemented "LPS4"
| STA -> IzvajalnikF4.sta state operand
| STB -> IzvajalnikF4.stb state operand
| STA -> IzvajalnikF4.sta state ea
| STB -> IzvajalnikF4.stb state ea
| STCH -> notImplemented "STCH4"
| STF -> notImplemented "STF4"
| STL -> IzvajalnikF4.stl state operand
| STS -> IzvajalnikF4.sts state operand
| STSW -> IzvajalnikF4.stsw state operand
| STT -> IzvajalnikF4.stt state operand
| STX -> IzvajalnikF4.stx state operand
| STL -> IzvajalnikF4.stl state ea
| STS -> IzvajalnikF4.sts state ea
| STSW -> IzvajalnikF4.stsw state ea
| STT -> IzvajalnikF4.stt state ea
| STX -> IzvajalnikF4.stx state ea
(* Control / IO *)
| TIX -> IzvajalnikF3.tix state operand

View file

@ -10,7 +10,8 @@ let run (state : Processor.state) (khz : float) : unit =
(*printni stanje*)
Printf.printf "After execution:\n";
Processor.print_regs state;
Processor.print_memory state 80;
Processor.print_memory_pretty state 160;
Printf.printf "-----------------------------------\n";
flush stdout;
(*spi*)

View file

@ -98,6 +98,27 @@ let print_memory (state : state) (n : int) : unit =
done;
Printf.printf "\n"
let print_memory_pretty (state : state) (n : int) : unit =
let mem = state.memory in
let len = Bytes.length mem in
let limit = min n len in
Printf.printf "Memory dump (first %d bytes):\n" limit;
for i = 0 to limit - 1 do
(* Print address at the start of each row *)
if i mod 16 = 0 then
Printf.printf "%04X: " i;
let byte = Char.code (Bytes.get mem i) in
Printf.printf "%02X " byte;
(* Newline after 16 bytes *)
if (i + 1) mod 16 = 0 then Printf.printf "\n";
done;
(* Final newline if last line was incomplete *)
if limit mod 16 <> 0 then Printf.printf "\n"
let print_regs state : unit =
let regs = state.regs in
Printf.printf "A: %06X\n" regs.a;