Changeset 3 for branches/bigint
- Timestamp:
- Aug 1, 2024, 10:09:05 PM (4 months ago)
- Location:
- branches/bigint
- Files:
-
- 4 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 -
branches/bigint/FormMain.pas
r2 r3 44 44 45 45 procedure TFormMain.FormShow(Sender: TObject); 46 var 47 Label1: TInt; 46 48 begin 47 49 with Machine.Memory do begin 48 50 WritePos(TInt(inLoadConst)); 49 WritePos( 0);51 WritePos(1000); 50 52 WritePos(Ord('A')); 53 54 WritePos(TInt(inLoadConst)); 55 WritePos(1001); 56 WritePos(20); 57 58 Label1 := Position; 59 51 60 WritePos(TInt(inOutput)); 52 61 WritePos(0); 53 WritePos(0); 54 WritePos(TInt(inLoad)); 55 WritePos(1); 56 WritePos(0); 62 WritePos(1000); 63 64 WritePos(TInt(inInc)); 65 WritePos(1000); 66 67 WritePos(TInt(inDec)); 68 WritePos(1001); 69 70 WritePos(TInt(inJumpNotZero)); 71 WritePos(1001); 72 WritePos(Label1); 73 57 74 WritePos(TInt(inHalt)); 58 75 end; -
branches/bigint/Memory.pas
r2 r3 22 22 function ReadPos: TInt; 23 23 property Size: TInt read GetSize write SetSize; 24 property Position: TInt read FPosition write FPosition; 24 25 end; 25 26
Note:
See TracChangeset
for help on using the changeset viewer.