Ignore:
Timestamp:
Aug 9, 2018, 10:49:33 AM (6 years ago)
Author:
chronos
Message:
  • Added: Support for more instructions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/virtcpu fixed int/UMachine.pas

    r165 r166  
    55{$DEFINE EXT_ARITHMETIC}
    66{$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}
    1113//{$DEFINE EXT_BLOCK}
    12 {$DEFINE EXT_GENERAL}
     14//{$DEFINE EXT_GENERAL}
    1315//{$DEFINE EXT_BIT}
    1416//{$DEFINE EXT_REL_JUMP}
     
    1820{$DEFINE EXT_STACK}
    1921{$ENDIF}
     22{$IFDEF EXT_MULTIPLICATION}
     23{$DEFINE EXT_ARITHMETIC}
     24{$ENDIF}
    2025
    2126
     
    3035  T = Integer;
    3136
    32   TOpcode = (opNop, opLoad, opHalt, opLoadConst, opLoadMem, opStoreMem, opNeg,
     37  TOpcode = (opNop, opLoad, opLoadConst, opNeg,
    3338    opJump, {$IFDEF EXT_REL_JUMP}opJumpRel,{$ENDIF}
    3439    opInc, opDec,
     40    {$IFDEF EXT_MEMORY}opLoadMem, opStoreMem,{$ENDIF}
    3541    {$IFDEF EXT_ARITHMETIC}opAdd, opSub,{$ENDIF}
    3642    {$IFDEF EXT_IO}opInput, opOutput,{$ENDIF}
     
    4147    {$IFDEF EXT_LOGICAL}opAnd, opOr, opXor,{$ENDIF}
    4248    {$IFDEF EXT_SHIFT}opShl, opShr,{$ENDIF}
     49    {$IFDEF EXT_ROTATION}opRor, opRol,{$ENDIF}
    4350    {$IFDEF EXT_STACK}opPush, opPop,{$ENDIF}
    4451    {$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
    4860  );
    4961
     
    6577    procedure OpcodeLoadConst;
    6678    procedure OpcodeJump;
     79    {$IFDEF EXT_REL_JUMP}
    6780    procedure OpcodeJumpRel;
     81    {$ENDIF}
    6882    procedure OpcodeNeg;
    6983    procedure OpcodeInc;
     
    92106    procedure OpcodeShr;
    93107    {$ENDIF}
     108    {$IFDEF EXT_ROTATION}
     109    procedure OpcodeRor;
     110    procedure OpcodeRol;
     111    {$ENDIF}
    94112    {$IFDEF EXT_LOGICAL}
    95113    procedure OpcodeAnd;
     
    103121    {$IFDEF EXT_SUBROUTINE}
    104122    procedure OpcodeCall;
     123    procedure OpcodeReturn;
    105124    {$IFDEF EXT_REL_JUMP}
    106125    procedure OpcodeCallRel;
    107126    {$ENDIF}
    108     procedure OpcodeReturn;
    109127    {$ENDIF}
    110128    {$IFDEF EXT_IO}
     
    115133    procedure OpcodeAdd;
    116134    procedure OpcodeSub;
     135    {$ENDIF}
     136    {$IFDEF EXT_MULTIPLICATION}
     137    procedure OpcodeMul;
     138    procedure OpcodeDiv;
    117139    {$ENDIF}
    118140  public
     
    224246end;
    225247
     248{$IFDEF EXT_REL_JUMP}
    226249procedure TCPU.OpcodeJumpRel;
    227250begin
    228251  IP := IP + ReadNext;
    229252end;
     253{$ENDIF}
    230254
    231255{$IFDEF EXT_CONDITIONAL}
     
    265289end;
    266290
     291
    267292{$IFDEF EXT_REL_JUMP}
    268293procedure TCPU.OpcodeJumpRelCond;
     
    271296end;
    272297{$ENDIF}
     298{$ENDIF}
     299
     300{$IFDEF EXT_ROTATION}
     301procedure TCPU.OpcodeRor;
     302var
     303  P1, P2: T;
     304begin
     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]));
     309end;
     310
     311procedure TCPU.OpcodeRol;
     312var
     313  P1, P2: T;
     314begin
     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));
     319end;
    273320{$ENDIF}
    274321
     
    425472  R2 := ReadNext;
    426473  Registers[R1] := Registers[R1] - Registers[R2];
     474end;
     475{$ENDIF}
     476
     477{$IFDEF EXT_MULTIPLICATION}
     478procedure TCPU.OpcodeMul;
     479var
     480  R1: T;
     481  R2: T;
     482begin
     483  R1 := ReadNext;
     484  R2 := ReadNext;
     485  Registers[R1] := Registers[R1] * Registers[R2];
     486end;
     487
     488procedure TCPU.OpcodeDiv;
     489var
     490  R1: T;
     491  R2: T;
     492begin
     493  R1 := ReadNext;
     494  R2 := ReadNext;
     495  Registers[R1] := Registers[R1] div Registers[R2];
    427496end;
    428497{$ENDIF}
     
    461530  OpcodeHandlers[opNeg] := OpcodeNeg;
    462531  OpcodeHandlers[opJump] := OpcodeJump;
     532  OpcodeHandlers[opInc] := OpcodeInc;
     533  OpcodeHandlers[opDec] := OpcodeDec;
    463534  {$IFDEF EXT_REL_JUMP}
    464535  OpcodeHandlers[opJumpRel] := OpcodeJumpRel;
     
    491562  OpcodeHandlers[opRet] := OpcodeReturn;
    492563  {$ENDIF}
     564  {$IFDEF EXT_ROTATION}
     565  OpcodeHandlers[opRor] := OpcodeRor;
     566  OpcodeHandlers[opRol] := OpcodeRol;
     567  {$ENDIF}
    493568  {$IFDEF EXT_IO}
    494569  OpcodeHandlers[opInput] := OpcodeInput;
    495570  OpcodeHandlers[opOutput] := OpcodeOutput;
    496571  {$ENDIF}
    497   OpcodeHandlers[opInc] := OpcodeInc;
    498   OpcodeHandlers[opDec] := OpcodeDec;
    499572  {$IFDEF EXT_ARITHMETIC}
    500573  OpcodeHandlers[opAdd] := OpcodeAdd;
    501574  OpcodeHandlers[opSub] := OpcodeSub;
    502575  {$ENDIF}
    503   {$IFDEF EXT_ARITHMETIC}
     576  {$IFDEF EXT_CONDITIONAL}
    504577  OpcodeHandlers[opJumpCond] := OpcodeJumpCond;
    505578  {$IFDEF EXT_REL_JUMP}
     
    510583  OpcodeHandlers[opTestLess] := OpcodeTestLess;
    511584  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;
    514591  {$ENDIF}
    515592end;
Note: See TracChangeset for help on using the changeset viewer.