176 lines
No EOL
5.2 KiB
OCaml
176 lines
No EOL
5.2 KiB
OCaml
(*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
|
|
|
|
(*Device specified by (m) <- (A)[rightmost byte]*)
|
|
let wd (state : Processor.state) (operand : int) : unit =
|
|
let charA = char_of_int (state.regs.a land 0xFF) in
|
|
match operand with
|
|
| 0 -> failwith "not implemented"
|
|
| 1 -> Printf.printf "[STDOUT]: %c\n" charA
|
|
| 2 -> failwith "not implemented"
|
|
| _ -> failwith "unsupporterd operand"
|
|
|
|
(*(A)[rightmost byte] <- Device specified by (m)*)
|
|
let rd (state : Processor.state) (operand : int) : unit =
|
|
match operand with
|
|
| 0 -> let charIn = input_char stdin in state.regs.a <- Char.code charIn
|
|
| 1 -> failwith "not implemented"
|
|
| 2 -> failwith "not implemented"
|
|
| _ -> failwith "unsupporterd 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 <- (0xFF land 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
|
|
|
|
let stch (state : Processor.state) (operand : int) : unit =
|
|
let byte = state.regs.a land 0xFF in
|
|
Bytes.set state.memory operand (char_of_int byte)
|
|
|
|
(* 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) |