koncal sicxe
This commit is contained in:
parent
ad8728bdf4
commit
303f5e06a7
5 changed files with 27 additions and 20 deletions
|
|
@ -21,8 +21,14 @@ let notImplemented (mnemonic : string) = Printf.printf "mnemonic %s is not imple
|
|||
let invalidOpcode (opcode : int) = Printf.printf "opcode %d is invalid!\n" opcode
|
||||
let invalidAdressing () = Printf.printf "invalid adressing!\n"
|
||||
|
||||
|
||||
|
||||
(*spremeni disp v signed če se uporablja PC-relativno*)
|
||||
let to_signed (x : int) : int =
|
||||
let mask12 = 0xFFF in (* keep only 12 bits *)
|
||||
let x = x land mask12 in (* mask input to 12 bits *)
|
||||
if x land 0x800 <> 0 then (* if the 24th bit (sign bit) is set *)
|
||||
x - (1 lsl 12) (* subtract 2^24 to get negative value *)
|
||||
else
|
||||
x
|
||||
|
||||
(*beri drugi byte ukaza formata 2 in vrni r1 in r2, kot int njunih vrednosti (reg a -> 1, reg x -> 2 ...)*)
|
||||
let readR1R2 (state : Processor.state) : (int * int) =
|
||||
|
|
@ -67,11 +73,11 @@ let readAddress (state : Processor.state) : int =
|
|||
let address = (addr_high lsl 8) lor byte4 in
|
||||
address
|
||||
|
||||
(*pridobi operand*)
|
||||
let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int =
|
||||
(*pridobi effective address in operand*)
|
||||
let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int * int=
|
||||
let ea =
|
||||
if nixbpe.b = 1 && nixbpe.p = 0 then state.regs.b + disp (*B relativno*)
|
||||
else if nixbpe.p = 1 && nixbpe.b = 0 then state.regs.pc + disp + 3(*PC relativno, ker PC povečamo šele po klicu te funkcije moramo tu +3*)
|
||||
else if nixbpe.p = 1 && nixbpe.b = 0 then state.regs.pc + to_signed disp + 3(*PC relativno, ker PC povečamo šele po klicu te funkcije moramo tu +3*)
|
||||
else disp (*direktno*)
|
||||
in
|
||||
let ea = if nixbpe.x = 1 then ea + state.regs.x else ea in (*+ (X) po potrebi*)
|
||||
|
|
@ -83,9 +89,9 @@ let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int
|
|||
else if nixbpe.n = 1 && nixbpe.i = 0 then Processor.readMemAddr state (Processor.readMemAddr state ea) (* indirect *)
|
||||
else failwith "Invalid addressing mode"
|
||||
in
|
||||
value
|
||||
ea ,value
|
||||
|
||||
let getOperandF4 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int =
|
||||
let getOperandF4 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int * int =
|
||||
let ea =
|
||||
if nixbpe.b = 1 && nixbpe.p = 0 then state.regs.b + disp (*B relativno*)
|
||||
else if nixbpe.p = 1 && nixbpe.b = 0 then state.regs.pc + disp + 4(*PC relativno, ker PC povečamo šele po klicu te funkcije moramo tu +4*)
|
||||
|
|
@ -100,7 +106,7 @@ let getOperandF4 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int
|
|||
else if nixbpe.n = 1 && nixbpe.i = 0 then Processor.readMemAddr state (Processor.readMemAddr state ea) (* indirect *)
|
||||
else failwith "Invalid addressing mode"
|
||||
in
|
||||
value
|
||||
ea, value
|
||||
|
||||
(*execute format 1*)
|
||||
let executeFormat1 (state : Processor.state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||
|
|
@ -147,7 +153,7 @@ let executeFormat2 (state: Processor.state) (mnemonic : OpcodeTable.mnemonic) :
|
|||
(*execute Format 3*)
|
||||
let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit =
|
||||
let disp = readDisp state in
|
||||
let operand = getOperandF3 state nixbpe disp in
|
||||
let ea ,operand = getOperandF3 state nixbpe disp in
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat3] Mnemonic: %s, nixbpe: %s, operand: %d = 0x%02X\n"
|
||||
(string_of_mnemonic mnemonic) (string_of_nixbpe nixbpe) operand operand;
|
||||
|
|
@ -168,11 +174,11 @@ let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
|
|||
| WD -> notImplemented "WD3"
|
||||
|
||||
(* Jump / subroutine *)
|
||||
| J -> IzvajalnikF3.j state operand
|
||||
| JEQ -> IzvajalnikF3.jeq state operand
|
||||
| JGT -> IzvajalnikF3.jgt state operand
|
||||
| JLT -> IzvajalnikF3.jlt state operand
|
||||
| JSUB -> IzvajalnikF3.jsub state operand
|
||||
| J -> IzvajalnikF3.j state ea
|
||||
| JEQ -> IzvajalnikF3.jeq state ea
|
||||
| JGT -> IzvajalnikF3.jgt state ea
|
||||
| JLT -> IzvajalnikF3.jlt state ea
|
||||
| JSUB -> IzvajalnikF3.jsub state ea
|
||||
| RSUB -> IzvajalnikF3.rsub state
|
||||
|
||||
(* Load/store *)
|
||||
|
|
@ -202,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 _, 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue