working...1
This commit is contained in:
parent
bc78a83838
commit
61bb14b9e3
21 changed files with 1054 additions and 12 deletions
155
ass2/SICocaml/sicxeDune/lib/izvajalnikF3.ml
Normal file
155
ass2/SICocaml/sicxeDune/lib/izvajalnikF3.ml
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
(*A <- (A)+ (m..m+2)*)
|
||||
let add (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA + operand
|
||||
|
||||
(*F (F) + (m..m+5)*)
|
||||
(*TODO check!*)
|
||||
let addf (state : Processor.state) (operand : int) : unit =
|
||||
let valF = state.regs.f in
|
||||
state.regs.f <- valF +. (float_of_int operand)
|
||||
|
||||
(*A <- (A) & (m..m+2)*)
|
||||
let andF (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA land operand
|
||||
|
||||
(*(A):(m..m+2)*)
|
||||
let comp (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.sw <- (if valA < operand then 0 else if valA = operand then 1 else 2)
|
||||
|
||||
(*A <- (A) / (m..m+2)*)
|
||||
let div (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA / operand
|
||||
|
||||
(*A <- (A) * (m..m+2)*)
|
||||
let mul (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA * operand
|
||||
|
||||
(*A <- (A) | (m..m+2)*)
|
||||
let orF (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA lor operand
|
||||
|
||||
(*A <- (A) - (m..m+2)*)
|
||||
let sub (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
state.regs.a <- valA - operand
|
||||
|
||||
(*PC <- m*)
|
||||
let j (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.pc <- operand
|
||||
|
||||
(*PC <- m if CC set to =*)
|
||||
let jeq (state : Processor.state) (operand : int) : unit =
|
||||
let cc = state.regs.sw in
|
||||
match cc with
|
||||
| 1 -> state.regs.pc <- operand
|
||||
| _ -> ()
|
||||
|
||||
(*PC <- m if CC set to >*)
|
||||
let jgt (state : Processor.state) (operand : int) : unit =
|
||||
let cc = state.regs.sw in
|
||||
match cc with
|
||||
| 2 -> state.regs.pc <- operand
|
||||
| _ -> ()
|
||||
|
||||
(*PC <- m if CC set to <*)
|
||||
let jlt (state : Processor.state) (operand : int) : unit =
|
||||
let cc = state.regs.sw in
|
||||
match cc with
|
||||
| 0 -> state.regs.pc <- operand
|
||||
| _ -> ()
|
||||
|
||||
(*L <- (PC); PC <- m*)
|
||||
let jsub (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.l <- state.regs.pc;
|
||||
state.regs.pc <- operand
|
||||
|
||||
(*PC <- (L)*)
|
||||
let rsub (state : Processor.state) : unit =
|
||||
state.regs.pc <- state.regs.l
|
||||
|
||||
(*A <- (m..m+2)*)
|
||||
let lda (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.a <- operand
|
||||
|
||||
(* LDB: B <- (m..m+2) *)
|
||||
let ldb (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.b <- operand
|
||||
|
||||
(*A [rightmost byte] ← (m)*)
|
||||
(*TODO*)
|
||||
let ldch (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.a <- operand
|
||||
|
||||
(* LDX: X <- (m..m+2) *)
|
||||
let ldx (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.x <- operand
|
||||
|
||||
(* LDL: L <- (m..m+2) *)
|
||||
let ldl (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.l <- operand
|
||||
|
||||
(* LDS: S <- (m..m+2) *)
|
||||
let lds (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.s <- operand
|
||||
|
||||
(* LDT: T <- (m..m+2) *)
|
||||
let ldt (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.t <- operand
|
||||
|
||||
(* LDF: F <- (m..m+5) *)
|
||||
(*TODO*)
|
||||
let ldf (state : Processor.state) (operand : float) : unit =
|
||||
state.regs.f <- operand
|
||||
|
||||
(*m..m+2 <- (A)*)
|
||||
let sta (state : Processor.state) (operand : int) : unit =
|
||||
let valA = state.regs.a in
|
||||
Processor.writeMemAddr state operand valA
|
||||
|
||||
(* m..m+2 <- (B) *)
|
||||
let stb (state : Processor.state) (operand : int) : unit =
|
||||
let valB = state.regs.b in
|
||||
Processor.writeMemAddr state operand valB
|
||||
|
||||
(* m..m+2 <- (X) *)
|
||||
let stx (state : Processor.state) (operand : int) : unit =
|
||||
let valX = state.regs.x in
|
||||
Processor.writeMemAddr state operand valX
|
||||
|
||||
(* m..m+2 <- (L) *)
|
||||
let stl (state : Processor.state) (operand : int) : unit =
|
||||
let valL = state.regs.l in
|
||||
Processor.writeMemAddr state operand valL
|
||||
|
||||
(* m..m+2 <- (S) *)
|
||||
let sts (state : Processor.state) (operand : int) : unit =
|
||||
let valS = state.regs.s in
|
||||
Processor.writeMemAddr state operand valS
|
||||
|
||||
(* m..m+2 <- (SW) *)
|
||||
let stsw (state : Processor.state) (operand : int) : unit =
|
||||
let valSW = state.regs.s in
|
||||
Processor.writeMemAddr state operand valSW
|
||||
|
||||
(* m..m+2 <- T register *)
|
||||
let stt (state : Processor.state) (operand : int) : unit =
|
||||
let valT = state.regs.t in
|
||||
Processor.writeMemAddr state operand valT
|
||||
|
||||
(* m..m+5 <- (F)*)
|
||||
(*TODO change*)
|
||||
let stf (state : Processor.state) (operand : int) : unit =
|
||||
let valF = state.regs.f in
|
||||
Processor.writeMemAddr state operand (int_of_float valF)
|
||||
|
||||
(*X <- (X) + 1; (X):(m..m+2)*)
|
||||
let tix (state : Processor.state) (operand : int) : unit =
|
||||
state.regs.x <- state.regs.x + 1;
|
||||
let valX = state.regs.x in
|
||||
state.regs.sw <- (if valX < operand then 0 else if valX = operand then 1 else 2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue