1 | unit Instructions;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Generics.Collections, Cpu;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TParamType = (ptNone, ptNumber, ptNumber8, ptNumber16, ptNumber32, ptNumber64,
|
---|
10 | ptReg, ptRegIndirect, ptRegIndirectIndex, ptRegIndirectGroup);
|
---|
11 | TParamTypeArray = array of TParamType;
|
---|
12 |
|
---|
13 | TInstructionInfo = class
|
---|
14 | Instruction: TInstruction;
|
---|
15 | Name: string;
|
---|
16 | Params: TParamTypeArray;
|
---|
17 | Description: string;
|
---|
18 | end;
|
---|
19 |
|
---|
20 | { TInstructionSet }
|
---|
21 |
|
---|
22 | TInstructionSet = class
|
---|
23 | Items: TObjectList<TInstructionInfo>;
|
---|
24 | function SearchName(Name: string): TInstructionInfo;
|
---|
25 | function SearchInstruction(Instruction: TInstruction): TInstructionInfo;
|
---|
26 | function AddNew(Instruction: TInstruction; Name: string;
|
---|
27 | Params: TParamTypeArray; Description: string): TInstructionInfo;
|
---|
28 | constructor Create;
|
---|
29 | destructor Destroy; override;
|
---|
30 | end;
|
---|
31 |
|
---|
32 |
|
---|
33 | implementation
|
---|
34 |
|
---|
35 |
|
---|
36 | { TInstructionSet }
|
---|
37 |
|
---|
38 | function TInstructionSet.SearchName(Name: string): TInstructionInfo;
|
---|
39 | var
|
---|
40 | I: Integer;
|
---|
41 | begin
|
---|
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;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | function TInstructionSet.SearchInstruction(Instruction: TInstruction
|
---|
49 | ): TInstructionInfo;
|
---|
50 | var
|
---|
51 | I: Integer;
|
---|
52 | begin
|
---|
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;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | function TInstructionSet.AddNew(Instruction: TInstruction; Name: string;
|
---|
60 | Params: TParamTypeArray; Description: string): TInstructionInfo;
|
---|
61 | begin
|
---|
62 | Result := TInstructionInfo.Create;
|
---|
63 | Result.Instruction := Instruction;
|
---|
64 | Result.Name := Name;
|
---|
65 | Result.Params := Params;
|
---|
66 | Result.Description := Description;
|
---|
67 | Items.Add(Result);
|
---|
68 | end;
|
---|
69 |
|
---|
70 | constructor TInstructionSet.Create;
|
---|
71 | begin
|
---|
72 | Items := TObjectList<TInstructionInfo>.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(inLoadImmediate, 'LDI', [ptReg, ptNumber], 'Sets register to immediate constant value.');
|
---|
76 | AddNew(inLoadImmediate8, 'LDI8', [ptReg, ptNumber8], 'Sets register to immediate constant value.');
|
---|
77 | AddNew(inLoadImmediate16, 'LDI16', [ptReg, ptNumber16], 'Sets register to immediate constant value.');
|
---|
78 | AddNew(inLoad, 'LD', [ptReg, ptReg], 'Copies value from one register to another.');
|
---|
79 | AddNew(inLoad8, 'LD8', [ptReg, ptReg], 'Copies value from one register to another.');
|
---|
80 | AddNew(inLoad16, 'LD16', [ptReg, ptReg], 'Copies value from one register to another.');
|
---|
81 | AddNew(inStore, 'ST', [ptRegIndirect, ptReg], 'Stores value from register to memory.');
|
---|
82 | AddNew(inStore8, 'ST8', [ptRegIndirect, ptReg], 'Stores value from register to memory.');
|
---|
83 | AddNew(inStore16, 'ST16', [ptRegIndirect, ptReg], 'Stores value from register to memory.');
|
---|
84 | AddNew(inInput, 'IN', [ptReg, ptRegIndirectGroup], 'Reads value from input port to register.');
|
---|
85 | AddNew(inInput8, 'IN', [ptReg, ptRegIndirectGroup], 'Reads value from input port to register.');
|
---|
86 | AddNew(inInput16, 'IN', [ptReg, ptRegIndirectGroup], 'Reads value from input port to register.');
|
---|
87 | AddNew(inOutput, 'OUT', [ptRegIndirectGroup, ptReg], 'Writes value from register to output port.');
|
---|
88 | AddNew(inOutput8, 'OUT8', [ptRegIndirectGroup, ptReg], 'Writes value from register to output port.');
|
---|
89 | AddNew(inOutput16, 'OUT16', [ptRegIndirectGroup, ptReg], 'Writes value from register to output port.');
|
---|
90 | AddNew(inJump, 'JP', [ptNumber], 'Unconditional absolute jump to defined address.');
|
---|
91 | end;
|
---|
92 |
|
---|
93 | destructor TInstructionSet.Destroy;
|
---|
94 | begin
|
---|
95 | FreeAndNil(Items);
|
---|
96 | inherited;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | end.
|
---|
100 |
|
---|