informatica:ae:execdrisc
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisioneRevisione precedente | |||
| informatica:ae:execdrisc [08/04/2011 alle 13:14 (15 anni fa)] – Marco Danelutto | informatica:ae:execdrisc [08/04/2011 alle 20:55 (15 anni fa)] (versione attuale) – Marco Danelutto | ||
|---|---|---|---|
| Linea 7: | Linea 7: | ||
| <code ocaml " | <code ocaml " | ||
| - | |||
| - | |||
| (** shortcut to maps ... *) | (** shortcut to maps ... *) | ||
| type assoc = Ass of string * int;; | type assoc = Ass of string * int;; | ||
| Linea 36: | Linea 34: | ||
| | | ||
| printf "PC=%d \n" !pc; | printf "PC=%d \n" !pc; | ||
| + | printf "%d registers. #MV = %d \n" | ||
| + | (Array.length r) (Array.length m); | ||
| pp_reg_set r; | pp_reg_set r; | ||
| pp_mem m | pp_mem m | ||
| Linea 43: | Linea 43: | ||
| @param i the instruction to be executed | @param i the instruction to be executed | ||
| @param env the initial environment. it is modified via side effects *) | @param env the initial environment. it is modified via side effects *) | ||
| - | let exec_i i env = | + | let step pgm env = |
| + | let apgm = Array.of_list (prog_to_asm pgm) in | ||
| match env with | match env with | ||
| Penv(pc, | Penv(pc, | ||
| - | (match i with | + | (let i = apgm.(!pc) in |
| + | match i with | ||
| ADD(Reg(a), | ADD(Reg(a), | ||
| | | | | ||
| Linea 98: | Linea 100: | ||
| then pc := !pc + l | then pc := !pc + l | ||
| else pc := !pc + 1 | else pc := !pc + 1 | ||
| - | | _ -> printf "UNINPLEMENTED") | + | | END -> failwith " |
| + | | _ -> printf "UNIMPLEMENTED: | ||
| ;; | ;; | ||
| Linea 114: | Linea 117: | ||
| | LabInstr(LabOff(l), | | LabInstr(LabOff(l), | ||
| ) | ) | ||
| + | ;; | ||
| + | |||
| + | let create_regs n = | ||
| + | Array.create n (ref 0);; | ||
| + | |||
| + | let stepper r m ipc prg steps = | ||
| + | let pc = ref ipc in | ||
| + | let reg = create_regs r in | ||
| + | let mem = create_regs m in | ||
| + | let penv = Penv(pc, | ||
| + | let aprg = Array.of_list prg in | ||
| + | |||
| + | for i=0 to steps do | ||
| + | printf " | ||
| + | (pp_instr !pc aprg.(i)); printf " | ||
| + | step prg penv; | ||
| + | dump penv; | ||
| + | done | ||
| ;; | ;; | ||
| </ | </ | ||
informatica/ae/execdrisc.1302268466.txt.gz · Ultima modifica: 08/04/2011 alle 13:14 (15 anni fa) da Marco Danelutto
