This commit is contained in:
Jaka Furlan 2025-11-30 13:53:18 +01:00
parent 61bb14b9e3
commit ad8728bdf4
19 changed files with 335 additions and 47 deletions

View file

@ -0,0 +1,30 @@
(*pogajalnik bo izvajal exekucijo eno za drugo*)
let run (state : Processor.state) (khz : float) : unit =
let perioda_sekunde = 1.0 /. (khz *. 1000.0) in
let rec loop state last_pc count=
(*izvedi ukaz*)
Izvajalnik.execute state;
(*printni stanje*)
Printf.printf "After execution:\n";
Processor.print_regs state;
Processor.print_memory state 50;
flush stdout;
(*spi*)
Unix.sleepf perioda_sekunde;(*mogoče spremeni na time of day approach , da se izogneš driftu*)
(*preveri ali je PC obtičan na istem mestu*)
let current_pc = state.regs.pc in
let count, last_pc =
if current_pc = last_pc then (count + 1, last_pc)
else (1, current_pc)
in
(*Nehaj rekurzijo če je PC 5x na istem mestu*)
if count >= 5 then
Printf.printf "PC stuck at 0x%X 5 times. Ending loop.\n" current_pc
else
loop state last_pc count
in loop state state.regs.pc 0