Changeset 166 for branches/virtcpu fixed int/UMachine.pas
- Timestamp:
- Aug 9, 2018, 10:49:33 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu fixed int/UMachine.pas
r165 r166 5 5 {$DEFINE EXT_ARITHMETIC} 6 6 {$DEFINE EXT_CONDITIONAL} 7 {$DEFINE EXT_LOGICAL} 8 {$DEFINE EXT_STACK} 9 {$DEFINE EXT_SUBROUTINE} 10 {$DEFINE EXT_SHIFT} 7 //{$DEFINE EXT_LOGICAL} 8 //{$DEFINE EXT_STACK} 9 //{$DEFINE EXT_SUBROUTINE} 10 //{$DEFINE EXT_ROTATION} 11 //{$DEFINE EXT_MULTIPLICATION} 12 //{$DEFINE EXT_SHIFT} 11 13 //{$DEFINE EXT_BLOCK} 12 {$DEFINE EXT_GENERAL}14 //{$DEFINE EXT_GENERAL} 13 15 //{$DEFINE EXT_BIT} 14 16 //{$DEFINE EXT_REL_JUMP} … … 18 20 {$DEFINE EXT_STACK} 19 21 {$ENDIF} 22 {$IFDEF EXT_MULTIPLICATION} 23 {$DEFINE EXT_ARITHMETIC} 24 {$ENDIF} 20 25 21 26 … … 30 35 T = Integer; 31 36 32 TOpcode = (opNop, opLoad, op Halt, opLoadConst, opLoadMem, opStoreMem, opNeg,37 TOpcode = (opNop, opLoad, opLoadConst, opNeg, 33 38 opJump, {$IFDEF EXT_REL_JUMP}opJumpRel,{$ENDIF} 34 39 opInc, opDec, 40 {$IFDEF EXT_MEMORY}opLoadMem, opStoreMem,{$ENDIF} 35 41 {$IFDEF EXT_ARITHMETIC}opAdd, opSub,{$ENDIF} 36 42 {$IFDEF EXT_IO}opInput, opOutput,{$ENDIF} … … 41 47 {$IFDEF EXT_LOGICAL}opAnd, opOr, opXor,{$ENDIF} 42 48 {$IFDEF EXT_SHIFT}opShl, opShr,{$ENDIF} 49 {$IFDEF EXT_ROTATION}opRor, opRol,{$ENDIF} 43 50 {$IFDEF EXT_STACK}opPush, opPop,{$ENDIF} 44 51 {$IFDEF EXT_CONDITIONAL} 45 opJumpRelCond, opJumpCond, opTestEqual, opTestNotEqual, opTestLess, 46 opTestLessEqual, opGreater, opGreaterEqual 47 {$ENDIF} 52 {$IFDEF EXT_REL_JUMP}opJumpRelCond,{$ENDIF} 53 opJumpCond, opTestEqual, opTestNotEqual, opTestLess, 54 opTestLessEqual, opTestGreater, opTestGreaterEqual, 55 {$ENDIF} 56 {$IFDEF EXT_MULTIPLICATION} 57 opMul, opDiv, 58 {$ENDIF} 59 opHalt 48 60 ); 49 61 … … 65 77 procedure OpcodeLoadConst; 66 78 procedure OpcodeJump; 79 {$IFDEF EXT_REL_JUMP} 67 80 procedure OpcodeJumpRel; 81 {$ENDIF} 68 82 procedure OpcodeNeg; 69 83 procedure OpcodeInc; … … 92 106 procedure OpcodeShr; 93 107 {$ENDIF} 108 {$IFDEF EXT_ROTATION} 109 procedure OpcodeRor; 110 procedure OpcodeRol; 111 {$ENDIF} 94 112 {$IFDEF EXT_LOGICAL} 95 113 procedure OpcodeAnd; … … 103 121 {$IFDEF EXT_SUBROUTINE} 104 122 procedure OpcodeCall; 123 procedure OpcodeReturn; 105 124 {$IFDEF EXT_REL_JUMP} 106 125 procedure OpcodeCallRel; 107 126 {$ENDIF} 108 procedure OpcodeReturn;109 127 {$ENDIF} 110 128 {$IFDEF EXT_IO} … … 115 133 procedure OpcodeAdd; 116 134 procedure OpcodeSub; 135 {$ENDIF} 136 {$IFDEF EXT_MULTIPLICATION} 137 procedure OpcodeMul; 138 procedure OpcodeDiv; 117 139 {$ENDIF} 118 140 public … … 224 246 end; 225 247 248 {$IFDEF EXT_REL_JUMP} 226 249 procedure TCPU.OpcodeJumpRel; 227 250 begin 228 251 IP := IP + ReadNext; 229 252 end; 253 {$ENDIF} 230 254 231 255 {$IFDEF EXT_CONDITIONAL} … … 265 289 end; 266 290 291 267 292 {$IFDEF EXT_REL_JUMP} 268 293 procedure TCPU.OpcodeJumpRelCond; … … 271 296 end; 272 297 {$ENDIF} 298 {$ENDIF} 299 300 {$IFDEF EXT_ROTATION} 301 procedure TCPU.OpcodeRor; 302 var 303 P1, P2: T; 304 begin 305 P1 := ReadNext; 306 P2 := ReadNext; 307 Registers[P1] := (Registers[P1] shr Registers[P2]) or 308 ((Registers[P1] and ((1 shl Registers[P2]) - 1)) shl (SizeOf(T) * 8 - Registers[P2])); 309 end; 310 311 procedure TCPU.OpcodeRol; 312 var 313 P1, P2: T; 314 begin 315 P1 := ReadNext; 316 P2 := ReadNext; 317 Registers[P1] := (Registers[P1] shl Registers[P2]) or 318 ((Registers[P1] shr (SizeOf(T) * 8 - Registers[P2])) and ((1 shl Registers[P2]) - 1)); 319 end; 273 320 {$ENDIF} 274 321 … … 425 472 R2 := ReadNext; 426 473 Registers[R1] := Registers[R1] - Registers[R2]; 474 end; 475 {$ENDIF} 476 477 {$IFDEF EXT_MULTIPLICATION} 478 procedure TCPU.OpcodeMul; 479 var 480 R1: T; 481 R2: T; 482 begin 483 R1 := ReadNext; 484 R2 := ReadNext; 485 Registers[R1] := Registers[R1] * Registers[R2]; 486 end; 487 488 procedure TCPU.OpcodeDiv; 489 var 490 R1: T; 491 R2: T; 492 begin 493 R1 := ReadNext; 494 R2 := ReadNext; 495 Registers[R1] := Registers[R1] div Registers[R2]; 427 496 end; 428 497 {$ENDIF} … … 461 530 OpcodeHandlers[opNeg] := OpcodeNeg; 462 531 OpcodeHandlers[opJump] := OpcodeJump; 532 OpcodeHandlers[opInc] := OpcodeInc; 533 OpcodeHandlers[opDec] := OpcodeDec; 463 534 {$IFDEF EXT_REL_JUMP} 464 535 OpcodeHandlers[opJumpRel] := OpcodeJumpRel; … … 491 562 OpcodeHandlers[opRet] := OpcodeReturn; 492 563 {$ENDIF} 564 {$IFDEF EXT_ROTATION} 565 OpcodeHandlers[opRor] := OpcodeRor; 566 OpcodeHandlers[opRol] := OpcodeRol; 567 {$ENDIF} 493 568 {$IFDEF EXT_IO} 494 569 OpcodeHandlers[opInput] := OpcodeInput; 495 570 OpcodeHandlers[opOutput] := OpcodeOutput; 496 571 {$ENDIF} 497 OpcodeHandlers[opInc] := OpcodeInc;498 OpcodeHandlers[opDec] := OpcodeDec;499 572 {$IFDEF EXT_ARITHMETIC} 500 573 OpcodeHandlers[opAdd] := OpcodeAdd; 501 574 OpcodeHandlers[opSub] := OpcodeSub; 502 575 {$ENDIF} 503 {$IFDEF EXT_ ARITHMETIC}576 {$IFDEF EXT_CONDITIONAL} 504 577 OpcodeHandlers[opJumpCond] := OpcodeJumpCond; 505 578 {$IFDEF EXT_REL_JUMP} … … 510 583 OpcodeHandlers[opTestLess] := OpcodeTestLess; 511 584 OpcodeHandlers[opTestLessEqual] := OpcodeTestLessEqual; 512 OpcodeHandlers[opGreater] := OpcodeTestGreat; 513 OpcodeHandlers[opGreaterEqual] := OpcodeTestGreatEqual; 585 OpcodeHandlers[opTestGreater] := OpcodeTestGreat; 586 OpcodeHandlers[opTestGreaterEqual] := OpcodeTestGreatEqual; 587 {$ENDIF} 588 {$IFDEF EXT_MULTIPLICATION} 589 OpcodeHandlers[opMul] := OpcodeMul; 590 OpcodeHandlers[opDiv] := OpcodeDiv; 514 591 {$ENDIF} 515 592 end;
Note:
See TracChangeset
for help on using the changeset viewer.