source: branches/bigint/Instructions.pas

Last change on this file was 7, checked in by chronos, 3 months ago
  • Added: More instructions implemented.
File size: 3.5 KB
Line 
1unit Instructions;
2
3interface
4
5uses
6 Classes, SysUtils, Generics.Collections, Cpu;
7
8type
9 TParamType = (ptNone, ptNumber, ptIndirect, ptIndirect2);
10 TParamTypeArray = array of TParamType;
11
12 TInstructionInfo = class
13 Instruction: TInstruction;
14 Name: string;
15 Params: TParamTypeArray;
16 Description: string;
17 end;
18
19 TInstructionInfos = TObjectList<TInstructionInfo>;
20
21 { TInstructionSet }
22
23 TInstructionSet = class
24 Items: TInstructionInfos;
25 function SearchName(Name: string): TInstructionInfo;
26 function SearchInstruction(Instruction: TInstruction): TInstructionInfo;
27 function AddNew(Instruction: TInstruction; Name: string;
28 Params: TParamTypeArray; Description: string): TInstructionInfo;
29 constructor Create;
30 destructor Destroy; override;
31 end;
32
33
34implementation
35
36{ TInstructionSet }
37
38function TInstructionSet.SearchName(Name: string): TInstructionInfo;
39var
40 I: Integer;
41begin
42 I := 0;
43 while (I < Items.Count) and (Items[I].Name <> Name) do Inc(I);
44 if I < Items.Count then Result := Items[I]
45 else Result := nil;
46end;
47
48function TInstructionSet.SearchInstruction(Instruction: TInstruction
49 ): TInstructionInfo;
50var
51 I: Integer;
52begin
53 I := 0;
54 while (I < Items.Count) and (Items[I].Instruction <> Instruction) do Inc(I);
55 if I < Items.Count then Result := Items[I]
56 else Result := nil;
57end;
58
59function TInstructionSet.AddNew(Instruction: TInstruction; Name: string;
60 Params: TParamTypeArray; Description: string): TInstructionInfo;
61begin
62 Result := TInstructionInfo.Create;
63 Result.Instruction := Instruction;
64 Result.Name := Name;
65 Result.Params := Params;
66 Result.Description := Description;
67 Items.Add(Result);
68end;
69
70constructor TInstructionSet.Create;
71begin
72 Items := TInstructionInfos.Create;
73 AddNew(inNop, 'NOP', [], 'No operation - The instruction doesn''t do anything.');
74 AddNew(inHalt, 'HALT', [], 'It terminates program execution and halts processor. Processor can be waked up by interrupt.');
75 AddNew(inLoadConst, 'LDC', [ptIndirect, ptNumber], 'Loads constant into address location.');
76 AddNew(inLoadIndex, 'LDI', [ptIndirect, ptIndirect, ptNumber], 'Loads value from one memory location with added relative index to another.');
77 AddNew(inLoad, 'LD', [ptIndirect, ptIndirect], 'Loads value from one memory location to another.');
78 AddNew(inLoadMem, 'LDM', [ptIndirect, ptIndirect2], 'Loads value from one indirect memory location to another.');
79 AddNew(inStoreMem, 'STM', [ptIndirect2, ptIndirect], 'Stotes value to indirect memory location from source location.');
80 AddNew(inInc, 'INC', [ptIndirect], 'Increments value in specified register.');
81 AddNew(inDec, 'DEC', [ptIndirect], 'Decrements value in specified register.');
82 AddNew(inInput, 'IN', [ptIndirect, ptIndirect], 'Reads value from input port to register.');
83 AddNew(inOutput, 'OUT', [ptIndirect, ptIndirect], 'Writes value from register to output port.');
84 AddNew(inJump, 'JP', [ptNumber], 'Unconditional absolute jump to defined address.');
85 AddNew(inJumpZero, 'JPZ', [ptIndirect, ptNumber], 'Jumps to given address if value of register is zero');
86 AddNew(inJumpNotZero, 'JPNZ', [ptIndirect, ptNumber], 'Jumps to given address if value of register is not zero');
87 AddNew(inPush, 'PUSH', [ptIndirect], 'Push memory location onto stack.');
88 AddNew(inPop, 'POP', [ptIndirect], 'Pop item from stack and store it into memory location.');
89 AddNew(inCall, 'CALL', [ptNumber], 'Call subroutine.');
90 AddNew(inRet, 'RET', [], 'Return from subrotine.');
91end;
92
93destructor TInstructionSet.Destroy;
94begin
95 FreeAndNil(Items);
96 inherited;
97end;
98
99end.
100
Note: See TracBrowser for help on using the repository browser.