Changeset 3 for branches/bigint


Ignore:
Timestamp:
Aug 1, 2024, 10:09:05 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Added more instructions.
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
  • branches/bigint/Cpu.pas

    r2 r3  
    99  TInstructionEvent = procedure of object;
    1010
    11   TInstruction = (inNop, inHalt, inLoad, inLoadConst, inInput, inOutput);
     11  TInstruction = (inNop, inHalt, inLoad, inLoadConst, inInput, inOutput,
     12    inJump, inJumpZero, inJumpNotZero, inInc, inDec);
    1213
    1314  { TCpu }
     
    2627    procedure InstructionInput;
    2728    procedure InstructionOutput;
     29    procedure InstructionInc;
     30    procedure InstructionDec;
     31    procedure InstructionJump;
     32    procedure InstructionJumpZero;
     33    procedure InstructionJumpNotZero;
    2834    procedure WriteMem(Address, Data: TInt);
    2935    function ReadMem(Address: TInt): TInt;
     
    95101end;
    96102
     103procedure TCpu.InstructionInc;
     104var
     105  Addr: TInt;
     106begin
     107  Addr := ReadMemPc;
     108  WriteMem(Addr, ReadMem(Addr) + 1);
     109end;
     110
     111procedure TCpu.InstructionDec;
     112var
     113  Addr: TInt;
     114begin
     115  Addr := ReadMemPc;
     116  WriteMem(Addr, ReadMem(Addr) - 1);
     117end;
     118
     119procedure TCpu.InstructionJump;
     120begin
     121  PC := ReadMem(ReadMemPc);
     122end;
     123
     124procedure TCpu.InstructionJumpZero;
     125var
     126  Condition: TInt;
     127  Addr: TInt;
     128begin
     129  Condition := ReadMemPc;
     130  Addr := ReadMemPc;
     131  if ReadMem(Condition) = 0 then PC := Addr;
     132end;
     133
     134procedure TCpu.InstructionJumpNotZero;
     135var
     136  Condition: TInt;
     137  Addr: TInt;
     138begin
     139  Condition := ReadMemPc;
     140  Addr := ReadMemPc;
     141  if ReadMem(Condition) <> 0 then PC := Addr;
     142end;
     143
    97144procedure TCpu.WriteMem(Address, Data: TInt);
    98145begin
     
    139186procedure TCpu.Step;
    140187var
    141   Opcode: TInt;
    142 begin
    143   Opcode := FOnReadMem(PC);
     188  Opcode: TInstruction;
     189begin
     190  Opcode := TInstruction(FOnReadMem(PC));
    144191  Inc(PC);
    145   Instructions[TInstruction(Opcode)];
     192  Instructions[Opcode];
    146193end;
    147194
     
    154201  Instructions[inInput] := InstructionInput;
    155202  Instructions[inOutput] := InstructionOutput;
     203  Instructions[inJump] := InstructionJump;
     204  Instructions[inJumpZero] := InstructionJumpZero;
     205  Instructions[inJumpNotZero] := InstructionJumpNotZero;
     206  Instructions[inInc] := InstructionInc;
     207  Instructions[inDec] := InstructionDec;
    156208end;
    157209
  • branches/bigint/FormMain.pas

    r2 r3  
    4444
    4545procedure TFormMain.FormShow(Sender: TObject);
     46var
     47  Label1: TInt;
    4648begin
    4749  with Machine.Memory do begin
    4850    WritePos(TInt(inLoadConst));
    49     WritePos(0);
     51    WritePos(1000);
    5052    WritePos(Ord('A'));
     53
     54    WritePos(TInt(inLoadConst));
     55    WritePos(1001);
     56    WritePos(20);
     57
     58    Label1 := Position;
     59
    5160    WritePos(TInt(inOutput));
    5261    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
    5774    WritePos(TInt(inHalt));
    5875  end;
  • branches/bigint/Memory.pas

    r2 r3  
    2222    function ReadPos: TInt;
    2323    property Size: TInt read GetSize write SetSize;
     24    property Position: TInt read FPosition write FPosition;
    2425  end;
    2526
Note: See TracChangeset for help on using the changeset viewer.