Ignore:
Timestamp:
Oct 16, 2018, 11:03:59 AM (6 years ago)
Author:
chronos
Message:
  • Added: Show CPU tick count.
  • Added: Show IP register value.
  • Modified: Condition instructions store result to R1 register rather then to condition boolean variable.
  • Modified: Shorter InstructionWriter method names.
File:
1 edited

Legend:

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

    r166 r168  
    55{$DEFINE EXT_ARITHMETIC}
    66{$DEFINE EXT_CONDITIONAL}
    7 //{$DEFINE EXT_LOGICAL}
    8 //{$DEFINE EXT_STACK}
    9 //{$DEFINE EXT_SUBROUTINE}
    10 //{$DEFINE EXT_ROTATION}
    11 //{$DEFINE EXT_MULTIPLICATION}
    12 //{$DEFINE EXT_SHIFT}
    13 //{$DEFINE EXT_BLOCK}
    14 //{$DEFINE EXT_GENERAL}
    15 //{$DEFINE EXT_BIT}
    16 //{$DEFINE EXT_REL_JUMP}
     7{$DEFINE EXT_LOGICAL}
     8{$DEFINE EXT_STACK}
     9{$DEFINE EXT_SUBROUTINE}
     10{$DEFINE EXT_ROTATION}
     11{$DEFINE EXT_MULTIPLICATION}
     12{$DEFINE EXT_SHIFT}
     13{$DEFINE EXT_BLOCK}
     14{$DEFINE EXT_GENERAL}
     15{$DEFINE EXT_BIT}
     16{$DEFINE EXT_REL_JUMP}
    1717
    1818// Extension dependencies
     
    5050    {$IFDEF EXT_STACK}opPush, opPop,{$ENDIF}
    5151    {$IFDEF EXT_CONDITIONAL}
    52     {$IFDEF EXT_REL_JUMP}opJumpRelCond,{$ENDIF}
    53     opJumpCond, opTestEqual, opTestNotEqual, opTestLess,
     52    {$IFDEF EXT_REL_JUMP}opJumpRelZero, opJumpRelNotZero,{$ENDIF}
     53    opJumpZero, opJumpNotZero, opTestEqual, opTestNotEqual, opTestLess,
    5454    opTestLessEqual, opTestGreater, opTestGreaterEqual,
    5555    {$ENDIF}
     
    9797    procedure OpcodeTestLessEqual;
    9898    procedure OpcodeTestLess;
    99     procedure OpcodeJumpCond;
     99    procedure OpcodeJumpCondNotZero;
     100    procedure OpcodeJumpCondZero;
    100101    {$IFDEF EXT_REL_JUMP}
    101     procedure OpcodeJumpRelCond;
     102    procedure OpcodeJumpRelCondNotZero;
     103    procedure OpcodeJumpRelCondZero;
    102104    {$ENDIF}
    103105    {$ENDIF}
     
    141143    Registers: array of T;
    142144    IP: T;
    143     {$IFDEF EXT_CONDITIONAL}
    144     Condition: Boolean;
    145     {$ENDIF}
    146145    {$IFDEF EXT_STACK}
    147146    SP: T;
     
    149148    Memory: array of T;
    150149    Terminated: Boolean;
     150    Ticks: Integer;
    151151    procedure Start;
    152152    procedure Stop;
     
    255255{$IFDEF EXT_CONDITIONAL}
    256256procedure TCPU.OpcodeTestEqual;
    257 begin
    258   Condition := ReadNext = ReadNext;
     257var
     258  P1, P2: T;
     259begin
     260  P1 := ReadNext;
     261  P2 := ReadNext;
     262  if Registers[P1] = Registers[P2] then Registers[P1] := 1
     263    else Registers[P1] := 0;
    259264end;
    260265
    261266procedure TCPU.OpcodeTestNotEqual;
    262 begin
    263   Condition := ReadNext <> ReadNext;
     267var
     268  P1, P2: T;
     269begin
     270  P1 := ReadNext;
     271  P2 := ReadNext;
     272  if Registers[P1] <> Registers[P2] then Registers[P1] := 1
     273    else Registers[P1] := 0;
    264274end;
    265275
    266276procedure TCPU.OpcodeTestGreatEqual;
    267 begin
    268   Condition := ReadNext >= ReadNext;
     277var
     278  P1, P2: T;
     279begin
     280  P1 := ReadNext;
     281  P2 := ReadNext;
     282  if Registers[P1] >= Registers[P2] then Registers[P1] := 1
     283    else Registers[P1] := 0;
    269284end;
    270285
    271286procedure TCPU.OpcodeTestGreat;
    272 begin
    273   Condition := ReadNext > ReadNext;
     287var
     288  P1, P2: T;
     289begin
     290  P1 := ReadNext;
     291  P2 := ReadNext;
     292  if Registers[P1] > Registers[P2] then Registers[P1] := 1
     293    else Registers[P1] := 0;
    274294end;
    275295
    276296procedure TCPU.OpcodeTestLessEqual;
    277 begin
    278   Condition := ReadNext <= ReadNext;
     297var
     298  P1, P2: T;
     299begin
     300  P1 := ReadNext;
     301  P2 := ReadNext;
     302  if Registers[P1] <= Registers[P2] then Registers[P1] := 1
     303    else Registers[P1] := 0;
    279304end;
    280305
    281306procedure TCPU.OpcodeTestLess;
    282 begin
    283   Condition := ReadNext < ReadNext;
    284 end;
    285 
    286 procedure TCPU.OpcodeJumpCond;
    287 begin
    288   if Condition then IP := ReadNext;
    289 end;
    290 
     307var
     308  P1, P2: T;
     309begin
     310  P1 := ReadNext;
     311  P2 := ReadNext;
     312  if Registers[P1] < Registers[P2] then Registers[P1] := 1
     313    else Registers[P1] := 0;
     314end;
     315
     316procedure TCPU.OpcodeJumpCondNotZero;
     317var
     318  P1, P2: T;
     319begin
     320  P1 := ReadNext;
     321  P2 := ReadNext;
     322  if Registers[P1] <> 0 then IP := P2;
     323end;
     324
     325procedure TCPU.OpcodeJumpCondZero;
     326var
     327  P1, P2: T;
     328begin
     329  P1 := ReadNext;
     330  P2 := ReadNext;
     331  if Registers[P1] = 0 then IP := P2;
     332end;
    291333
    292334{$IFDEF EXT_REL_JUMP}
    293 procedure TCPU.OpcodeJumpRelCond;
    294 begin
    295   if Condition then IP := IP + ReadNext;
     335procedure TCPU.OpcodeJumpRelCondZero;
     336var
     337  P1, P2: T;
     338begin
     339  P1 := ReadNext;
     340  P2 := ReadNext;
     341  if P1 = 0 then IP := IP + P2;
     342end;
     343
     344procedure TCPU.OpcodeJumpRelCondNotZero;
     345var
     346  P1, P2: T;
     347begin
     348  P1 := ReadNext;
     349  P2 := ReadNext;
     350  if P1 <> 0 then IP := IP + P2;
    296351end;
    297352{$ENDIF}
     
    503558  Terminated := False;
    504559  IP := 0;
     560  Ticks := 0;
    505561  {$IFDEF EXT_STACK}
    506562  SP := Length(Memory);
     
    511567      OpcodeHandlers[TOpcode(Opcode)]
    512568      else raise Exception.Create(Format('Unsupported instruction %d', [Opcode]));
     569    Inc(Ticks);
    513570  end;
    514571end;
     
    575632  {$ENDIF}
    576633  {$IFDEF EXT_CONDITIONAL}
    577   OpcodeHandlers[opJumpCond] := OpcodeJumpCond;
     634  OpcodeHandlers[opJumpZero] := OpcodeJumpCondZero;
     635  OpcodeHandlers[opJumpNotZero] := OpcodeJumpCondNotZero;
    578636  {$IFDEF EXT_REL_JUMP}
    579   OpcodeHandlers[opJumpRelCond] := OpcodeJumpRelCond;
     637  OpcodeHandlers[opJumpRelZero] := OpcodeJumpRelCondZero;
     638  OpcodeHandlers[opJumpRelNotZero] := OpcodeJumpRelCondNotZero;
    580639  {$ENDIF}
    581640  OpcodeHandlers[opTestEqual] := OpcodeTestEqual;
Note: See TracChangeset for help on using the changeset viewer.