Changeset 3 for branches/bigint/Cpu.pas
- Timestamp:
- Aug 1, 2024, 10:09:05 PM (3 months ago)
- Location:
- branches/bigint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bigint
-
Property svn:ignore
set to
BigIntVM
BigIntVM.lps
BigIntVM.res
BigIntVM.dbg
lib
-
Property svn:ignore
set to
-
branches/bigint/Cpu.pas
r2 r3 9 9 TInstructionEvent = procedure of object; 10 10 11 TInstruction = (inNop, inHalt, inLoad, inLoadConst, inInput, inOutput); 11 TInstruction = (inNop, inHalt, inLoad, inLoadConst, inInput, inOutput, 12 inJump, inJumpZero, inJumpNotZero, inInc, inDec); 12 13 13 14 { TCpu } … … 26 27 procedure InstructionInput; 27 28 procedure InstructionOutput; 29 procedure InstructionInc; 30 procedure InstructionDec; 31 procedure InstructionJump; 32 procedure InstructionJumpZero; 33 procedure InstructionJumpNotZero; 28 34 procedure WriteMem(Address, Data: TInt); 29 35 function ReadMem(Address: TInt): TInt; … … 95 101 end; 96 102 103 procedure TCpu.InstructionInc; 104 var 105 Addr: TInt; 106 begin 107 Addr := ReadMemPc; 108 WriteMem(Addr, ReadMem(Addr) + 1); 109 end; 110 111 procedure TCpu.InstructionDec; 112 var 113 Addr: TInt; 114 begin 115 Addr := ReadMemPc; 116 WriteMem(Addr, ReadMem(Addr) - 1); 117 end; 118 119 procedure TCpu.InstructionJump; 120 begin 121 PC := ReadMem(ReadMemPc); 122 end; 123 124 procedure TCpu.InstructionJumpZero; 125 var 126 Condition: TInt; 127 Addr: TInt; 128 begin 129 Condition := ReadMemPc; 130 Addr := ReadMemPc; 131 if ReadMem(Condition) = 0 then PC := Addr; 132 end; 133 134 procedure TCpu.InstructionJumpNotZero; 135 var 136 Condition: TInt; 137 Addr: TInt; 138 begin 139 Condition := ReadMemPc; 140 Addr := ReadMemPc; 141 if ReadMem(Condition) <> 0 then PC := Addr; 142 end; 143 97 144 procedure TCpu.WriteMem(Address, Data: TInt); 98 145 begin … … 139 186 procedure TCpu.Step; 140 187 var 141 Opcode: TIn t;142 begin 143 Opcode := FOnReadMem(PC);188 Opcode: TInstruction; 189 begin 190 Opcode := TInstruction(FOnReadMem(PC)); 144 191 Inc(PC); 145 Instructions[ TInstruction(Opcode)];192 Instructions[Opcode]; 146 193 end; 147 194 … … 154 201 Instructions[inInput] := InstructionInput; 155 202 Instructions[inOutput] := InstructionOutput; 203 Instructions[inJump] := InstructionJump; 204 Instructions[inJumpZero] := InstructionJumpZero; 205 Instructions[inJumpNotZero] := InstructionJumpNotZero; 206 Instructions[inInc] := InstructionInc; 207 Instructions[inDec] := InstructionDec; 156 208 end; 157 209
Note:
See TracChangeset
for help on using the changeset viewer.