working on ass3, todo pc, nixbpe

This commit is contained in:
Jaka Furlan 2025-12-14 23:31:52 +01:00
parent 6261d9fe37
commit beabcde7db
15 changed files with 412 additions and 194 deletions

View file

@ -74,7 +74,7 @@ let readAddress (state : Processor.state) : int =
address
(*pridobi effective address in operand*)
let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int * int=
let getOperandF3 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : 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 + to_signed disp + 3(*PC relativno, ker PC povečamo šele po klicu te funkcije moramo tu +3*)
@ -89,7 +89,13 @@ 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
ea ,value
let valueMem =
if nixbpe.n = 1 && nixbpe.i = 1 then ea
else if nixbpe.n = 0 && nixbpe.i = 1 then ea (* immediate value *)
else if nixbpe.n = 1 && nixbpe.i = 0 then Processor.readMemAddr state ea (* indirect *)
else failwith "Invalid addressing mode"
in
ea ,value, valueMem
let getOperandF4 (state : Processor.state) (nixbpe : nixbpe) (disp : int) : int * int =
let ea =
@ -153,7 +159,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 ea ,operand = getOperandF3 state nixbpe disp in
let ea ,operand, valueMem = 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;
@ -191,15 +197,15 @@ let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
| LDT -> IzvajalnikF3.ldt state operand
| LDX -> IzvajalnikF3.ldx state operand
| LPS -> notImplemented "LPS4"
| STA -> IzvajalnikF3.sta state ea
| STB -> IzvajalnikF3.stb state ea
| STCH -> IzvajalnikF3.stch state ea
| STA -> IzvajalnikF3.sta state valueMem
| STB -> IzvajalnikF3.stb state valueMem
| STCH -> IzvajalnikF3.stch state valueMem
| STF -> notImplemented "STF4"
| STL -> IzvajalnikF3.stl state ea
| STS -> IzvajalnikF3.sts state ea
| STSW -> IzvajalnikF3.stsw state ea
| STT -> IzvajalnikF3.stt state ea
| STX -> IzvajalnikF3.stx state ea
| STL -> IzvajalnikF3.stl state valueMem
| STS -> IzvajalnikF3.sts state valueMem
| STSW -> IzvajalnikF3.stsw state valueMem
| STT -> IzvajalnikF3.stt state valueMem
| STX -> IzvajalnikF3.stx state valueMem
(* Control / IO *)
| TIX -> IzvajalnikF3.tix state operand

View file

@ -41,7 +41,8 @@ let writeMemAddr (state : state) (address : int) (value : int) : unit =
let byte1 = Char.chr ((value lsr 16) land 0xFF) in
let byte2 = Char.chr ((value lsr 8) land 0xFF) in
let byte3 = Char.chr (value land 0xFF) in
Printf.printf "[Procesor/writeMemAddr]Napisal byte %02X %02X %02X na %06X\n"
(int_of_char byte1) (int_of_char byte2) (int_of_char byte3) address;
(* Write bytes into memory *)
Bytes.set state.memory address byte1;
Bytes.set state.memory (address+1) byte2;