Changeset 164 for branches/virtcpu fixed int
- Timestamp:
- Aug 7, 2018, 5:30:22 PM (6 years ago)
- Location:
- branches/virtcpu fixed int
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu fixed int/UFormMain.lfm
r163 r164 1 1 object Form1: TForm1 2 Left = 4 492 Left = 456 3 3 Height = 762 4 Top = 1 454 Top = 163 5 5 Width = 1286 6 6 Caption = 'Form1' -
branches/virtcpu fixed int/UMachine.pas
r163 r164 1 1 unit UMachine; 2 3 {$DEFINE EXT_MEMORY} 4 {$DEFINE EXT_IO} 5 {$DEFINE EXT_ARITHMETIC} 6 {$DEFINE EXT_CONDITIONAL} 7 //{$DEFINE EXT_LOGICAL} 8 {$DEFINE EXT_STACK} 9 {$DEFINE EXT_SUBROUTINE} 10 //{$DEFINE EXT_SHIFT} 11 //{$DEFINE EXT_BLOCK} 12 {$DEFINE EXT_GENERAL} 13 //{$DEFINE EXT_BIT} 14 15 // Extension dependencies 16 {$IFDEF EXT_SUBROUTINE} 17 {$DEFINE EXT_STACK} 18 {$ENDIF} 19 2 20 3 21 {$mode delphi}{$H+} … … 12 30 13 31 TOpcode = (opNop, opLoad, opHalt, opLoadConst, opLoadMem, opStoreMem, opNeg, 14 opJump, opJumpRel, opPush, opPop, opCall, opCallRel, opRet, opInput, 15 opOutput, opInc, opDec); 32 opJump, opJumpRel, opCall, opCallRel, opRet, opInput, 33 opOutput, opInc, opDec, opAdd, opSub, opExchg, 34 {$IFDEF EXT_STACK} 35 opPush, opPop, 36 {$ENDIF} 37 {$IFDEF EXT_CONDITIONAL} 38 opJumpRelCond, opJumpCond, opTestEqual, opTestNotEqual, opTestLess, 39 opTestLessEqual, opGreater, opGreaterEqual 40 {$ENDIF} 41 ); 16 42 17 43 TOpcodeHandler = procedure of object; … … 31 57 procedure OpcodeLoad; 32 58 procedure OpcodeLoadConst; 59 {$IFDEF EXT_MEMORY} 33 60 procedure OpcodeLoadMem; 34 61 procedure OpcodeStoreMem; 62 {$ENDIF} 35 63 procedure OpcodeNeg; 64 {$IFDEF EXT_GENERAL} 65 procedure OpcodeExchange; 66 {$ENDIF} 36 67 procedure OpcodeJump; 37 68 procedure OpcodeJumpRel; 69 {$IFDEF EXT_CONDITIONAL} 70 procedure OpcodeTestEqual; 71 procedure OpcodeTestNotEqual; 72 procedure OpcodeTestGreatEqual; 73 procedure OpcodeTestGreat; 74 procedure OpcodeTestLessEqual; 75 procedure OpcodeTestLess; 76 procedure OpcodeJumpCond; 77 procedure OpcodeJumpRelCond; 78 {$ENDIF} 79 {$IFDEF EXT_STACK} 38 80 procedure OpcodePush; 39 81 procedure OpcodePop; 82 {$ENDIF} 83 {$IFDEF EXT_SUBROUTINE} 40 84 procedure OpcodeCall; 41 85 procedure OpcodeCallRel; 42 86 procedure OpcodeReturn; 87 {$ENDIF} 88 {$IFDEF EXT_IO} 43 89 procedure OpcodeOutput; 44 90 procedure OpcodeInput; 91 {$ENDIF} 45 92 procedure OpcodeInc; 46 93 procedure OpcodeDec; 94 {$IFDEF EXT_ARITHMETIC} 95 procedure OpcodeAdd; 96 procedure OpcodeSub; 97 {$ENDIF} 47 98 public 48 99 Registers: array of T; 49 100 IP: T; 101 {$IFDEF EXT_CONDITIONAL} 102 Condition: Boolean; 103 {$ENDIF} 104 {$IFDEF EXT_STACK} 50 105 SP: T; 106 {$ENDIF} 51 107 Memory: array of T; 52 108 Terminated: Boolean; … … 100 156 end; 101 157 158 {$IFDEF EXT_MEMORY} 102 159 procedure TCPU.OpcodeLoadMem; 103 160 var … … 119 176 Memory[Registers[P1]] := Registers[P2]; 120 177 end; 178 {$ENDIF} 121 179 122 180 procedure TCPU.OpcodeNeg; … … 128 186 end; 129 187 188 {$IFDEF EXT_GENERAL} 189 procedure TCPU.OpcodeExchange; 190 var 191 P1, P2, Temp: T; 192 begin 193 P1 := ReadNext; 194 P2 := ReadNext; 195 Temp := Registers[P1]; 196 Registers[P1] := Registers[P2]; 197 Registers[P2] := Temp; 198 end; 199 {$ENDIF} 200 130 201 procedure TCPU.OpcodeJump; 131 202 begin … … 138 209 end; 139 210 211 {$IFDEF EXT_CONDITIONAL} 212 procedure TCPU.OpcodeTestEqual; 213 begin 214 Condition := ReadNext = ReadNext; 215 end; 216 217 procedure TCPU.OpcodeTestNotEqual; 218 begin 219 Condition := ReadNext <> ReadNext; 220 end; 221 222 procedure TCPU.OpcodeTestGreatEqual; 223 begin 224 Condition := ReadNext >= ReadNext; 225 end; 226 227 procedure TCPU.OpcodeTestGreat; 228 begin 229 Condition := ReadNext > ReadNext; 230 end; 231 232 procedure TCPU.OpcodeTestLessEqual; 233 begin 234 Condition := ReadNext <= ReadNext; 235 end; 236 237 procedure TCPU.OpcodeTestLess; 238 begin 239 Condition := ReadNext < ReadNext; 240 end; 241 242 procedure TCPU.OpcodeJumpCond; 243 begin 244 if Condition then IP := ReadNext; 245 end; 246 247 procedure TCPU.OpcodeJumpRelCond; 248 begin 249 if Condition then IP := IP + ReadNext; 250 end; 251 {$ENDIF} 252 253 {$IFDEF EXT_STACK} 140 254 procedure TCPU.OpcodePush; 141 255 begin … … 149 263 Registers[ReadNext] := Memory[SP]; 150 264 end; 151 265 {$ENDIF} 266 267 {$IFDEF EXT_SUBROUTINE} 152 268 procedure TCPU.OpcodeCall; 153 269 var … … 175 291 IP := Memory[SP]; 176 292 end; 177 293 {$ENDIF} 294 295 {$IFDEF EXT_IO} 178 296 procedure TCPU.OpcodeOutput; 179 297 var … … 197 315 Registers[R1] := FOnInput(Registers[R2]); 198 316 end; 317 {$ENDIF} 199 318 200 319 procedure TCPU.OpcodeInc; … … 214 333 end; 215 334 335 {$IFDEF EXT_ARITHMETIC} 336 procedure TCPU.OpcodeAdd; 337 var 338 R1: T; 339 R2: T; 340 begin 341 R1 := ReadNext; 342 R2 := ReadNext; 343 Registers[R1] := Registers[R1] + Registers[R2]; 344 end; 345 346 procedure TCPU.OpcodeSub; 347 var 348 R1: T; 349 R2: T; 350 begin 351 R1 := ReadNext; 352 R2 := ReadNext; 353 Registers[R1] := Registers[R1] - Registers[R2]; 354 end; 355 {$ENDIF} 356 216 357 procedure TCPU.Start; 217 358 var … … 220 361 Terminated := False; 221 362 IP := 0; 363 {$IFDEF EXT_STACK} 222 364 SP := Length(Memory); 365 {$ENDIF} 223 366 while not Terminated do begin 224 367 Opcode := ReadNext; … … 243 386 OpcodeHandlers[opHalt] := OpcodeHalt; 244 387 OpcodeHandlers[opLoadConst] := OpcodeLoadConst; 388 {$IFDEF EXT_MEMORY} 245 389 OpcodeHandlers[opLoadMem] := OpcodeLoadMem; 246 390 OpcodeHandlers[opStoreMem] := OpcodeStoreMem; 391 {$ENDIF} 247 392 OpcodeHandlers[opNeg] := OpcodeNeg; 248 393 OpcodeHandlers[opJump] := OpcodeJump; 249 394 OpcodeHandlers[opJumpRel] := OpcodeJumpRel; 395 {$IFDEF EXT_GENERAL} 396 OpcodeHandlers[opExchg] := OpcodeExchange; 397 {$ENDIF} 398 {$IFDEF EXT_STACK} 250 399 OpcodeHandlers[opPush] := OpcodePush; 251 400 OpcodeHandlers[opPop] := OpcodePop; 401 {$ENDIF} 402 {$IFDEF EXT_SUBROUTINE} 252 403 OpcodeHandlers[opCall] := OpcodeCall; 253 404 OpcodeHandlers[opCallRel] := OpcodeCallRel; 254 405 OpcodeHandlers[opRet] := OpcodeReturn; 406 {$ENDIF} 407 {$IFDEF EXT_IO} 255 408 OpcodeHandlers[opInput] := OpcodeInput; 256 409 OpcodeHandlers[opOutput] := OpcodeOutput; 410 {$ENDIF} 257 411 OpcodeHandlers[opInc] := OpcodeInc; 258 412 OpcodeHandlers[opDec] := OpcodeDec; 413 {$IFDEF EXT_ARITHMETIC} 414 OpcodeHandlers[opAdd] := OpcodeAdd; 415 OpcodeHandlers[opSub] := OpcodeSub; 416 {$ENDIF} 417 {$IFDEF EXT_ARITHMETIC} 418 OpcodeHandlers[opJumpCond] := OpcodeJumpCond; 419 OpcodeHandlers[opJumpRelCond] := OpcodeJumpRelCond; 420 OpcodeHandlers[opTestEqual] := OpcodeTestEqual; 421 OpcodeHandlers[opTestNotEqual] := OpcodeTestNotEqual; 422 OpcodeHandlers[opTestLess] := OpcodeTestLess; 423 OpcodeHandlers[opTestLessEqual] := OpcodeTestLessEqual; 424 OpcodeHandlers[opGreater] := OpcodeTestGreat; 425 OpcodeHandlers[opGreaterEqual] := OpcodeTestGreatEqual; 426 {$ENDIF} 259 427 end; 260 428
Note:
See TracChangeset
for help on using the changeset viewer.