Changeset 59 for branches/ByteArray/Instructions.pas
- Timestamp:
- Nov 25, 2023, 11:47:52 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray/Instructions.pas
r56 r59 7 7 8 8 type 9 TParamType = (ptNone, pt Number, ptReg, ptRegIndirect, ptRegIndirectIndex,10 pt Size);9 TParamType = (ptNone, ptRegIndirectIndex, ptRegIndirect, ptReg, 10 ptDataWidth, ptAddressWidth, ptData, ptAddress); 11 11 TParamTypeArray = array of TParamType; 12 12 … … 18 18 end; 19 19 20 { TInstruction Set}20 { TInstructionInfos } 21 21 22 TInstruction Set = class23 Items: TObjectList<TInstructionInfo>;24 function Search Name(Name: string): TInstructionInfo;22 TInstructionInfos = class(TObjectList<TInstructionInfo>) 23 function SearchByName(Name: string): TInstructionInfo; 24 function SearchByNameMultiple(Name: string): TInstructionInfos; 25 25 function SearchInstruction(Instruction: TInstruction): TInstructionInfo; 26 26 function AddNew(Instruction: TInstruction; Name: string; 27 27 Params: TParamTypeArray; Description: string): TInstructionInfo; 28 constructor Create; 29 destructor Destroy; override; 28 procedure Init; 30 29 end; 30 31 const 32 ParamTypeString: array[TParamType] of string = ('None', 'Data', 'Address', 33 'Register', 'Indirect register', 'Indirect indexed register', 34 'Data width', 'Address width'); 31 35 32 36 33 37 implementation 34 38 35 { TInstruction Set}39 { TInstructionInfos } 36 40 37 function TInstruction Set.SearchName(Name: string): TInstructionInfo;41 function TInstructionInfos.SearchByName(Name: string): TInstructionInfo; 38 42 var 39 43 I: Integer; 40 44 begin 41 45 I := 0; 42 while (I < Items.Count) and (Items[I].Name <> Name) do Inc(I);43 if I < Items.Count then Result := Items[I]46 while (I < Count) and (Items[I].Name <> Name) do Inc(I); 47 if I < Count then Result := Items[I] 44 48 else Result := nil; 45 49 end; 46 50 47 function TInstructionSet.SearchInstruction(Instruction: TInstruction 51 function TInstructionInfos.SearchByNameMultiple(Name: string 52 ): TInstructionInfos; 53 var 54 I: Integer; 55 begin 56 Result := TInstructionInfos.Create(False); 57 for I := 0 to Count - 1 do 58 if Items[I].Name = Name then Result.Add(Items[I]); 59 end; 60 61 function TInstructionInfos.SearchInstruction(Instruction: TInstruction 48 62 ): TInstructionInfo; 49 63 var … … 51 65 begin 52 66 I := 0; 53 while (I < Items.Count) and (Items[I].Instruction <> Instruction) do Inc(I);54 if I < Items.Count then Result := Items[I]67 while (I < Count) and (Items[I].Instruction <> Instruction) do Inc(I); 68 if I < Count then Result := Items[I] 55 69 else Result := nil; 56 70 end; 57 71 58 function TInstruction Set.AddNew(Instruction: TInstruction; Name: string;72 function TInstructionInfos.AddNew(Instruction: TInstruction; Name: string; 59 73 Params: TParamTypeArray; Description: string): TInstructionInfo; 60 74 begin … … 64 78 Result.Params := Params; 65 79 Result.Description := Description; 66 Items.Add(Result);80 Add(Result); 67 81 end; 68 82 69 constructor TInstructionSet.Create;83 procedure TInstructionInfos.Init; 70 84 begin 71 Items := TObjectList<TInstructionInfo>.Create;85 Clear; 72 86 AddNew(inNop, 'NOP', [], 'No operation - The instruction doesn''t do anything.'); 73 87 AddNew(inHalt, 'HALT', [], 'It terminates program execution and halts processor. Processor can be waked up by interrupt.'); 74 AddNew(inLoadConst, 'LD', [ptReg, pt Number], 'Sets register to immediate constant value.');75 AddNew(inLoadConstSize, 'LD', [pt Size, ptReg, ptNumber], 'Sets register to immediate constant value.');88 AddNew(inLoadConst, 'LD', [ptReg, ptData], 'Sets register to immediate constant value.'); 89 AddNew(inLoadConstSize, 'LD', [ptDataWidth, ptReg, ptData], 'Sets register to immediate constant value.'); 76 90 AddNew(inLoad, 'LD', [ptReg, ptReg], 'Copies value from one register to another.'); 91 AddNew(inLoadSize, 'LD', [ptDataWidth, ptReg, ptReg], 'Copies value from one register to another.'); 92 AddNew(inLoadMem, 'LD', [ptReg, ptRegIndirect], 'Loads value from memory to register.'); 93 AddNew(inLoadMemSize, 'LD', [ptDataWidth, ptReg, ptRegIndirect], 'Loads value from memory to register.'); 94 AddNew(inStoreMem, 'LD', [ptRegIndirect, ptReg], 'Stores value from register to memory.'); 95 AddNew(inStoreMemSize, 'LD', [ptDataWidth, ptRegIndirect, ptReg], 'Stores value from register to memory.'); 96 AddNew(inLoadMemIndex, 'LD', [ptReg, ptRegIndirectIndex], 'Loads value from memory with numeric index to register.'); 97 AddNew(inLoadMemIndexSize, 'LD', [ptDataWidth, ptReg, ptRegIndirectIndex], 'Loads value from memory with numeric index to register.'); 98 AddNew(inStoreMemIndex, 'LD', [ptRegIndirectIndex, ptReg], 'Stores value from register to memory with numeric index.'); 99 AddNew(inStoreMemIndexSize, 'LD', [ptDataWidth, ptRegIndirectIndex, ptReg], 'Stores value from register to memory with numeric index.'); 77 100 AddNew(inInc, 'INC', [ptReg], 'Increments value in specified register.'); 101 AddNew(inIncSize, 'INC', [ptDataWidth, ptReg], 'Increments value in specified register.'); 78 102 AddNew(inDec, 'DEC', [ptReg], 'Decrements value in specified register.'); 79 AddNew(inLoadMem, 'LD', [ptReg, ptRegIndirect], 'Loads value from memory to register.'); 80 AddNew(inStoreMem, 'ST', [ptRegIndirect, ptReg], 'Stores value from register to memory.'); 103 AddNew(inDecSize, 'DEC', [ptDataWidth, ptReg], 'Decrements value in specified register.'); 81 104 AddNew(inAdd, 'ADD', [ptReg, ptReg], 'Adds second register to first register.'); 105 AddNew(inAddSize, 'ADD', [ptDataWidth, ptReg, ptReg], 'Adds second register to first register.'); 82 106 AddNew(inSub, 'SUB', [ptReg, ptReg], 'Subtracts second register from first register.'); 107 AddNew(inSubSize, 'SUB', [ptDataWidth, ptReg, ptReg], 'Subtracts second register from first register.'); 83 108 AddNew(inInput, 'IN', [ptReg, ptRegIndirect], 'Reads value from input port to register.'); 84 109 AddNew(inOutput, 'OUT', [ptRegIndirect, ptReg], 'Writes value from register to output port.'); 85 AddNew(inJumpZero, 'JZ', [ptReg, pt Number], 'Jumps to given address if value of register is zero');86 AddNew(inJumpNotZero, 'JNZ', [ptReg, pt Number], 'Jumps to given address if value of register is not zero');110 AddNew(inJumpZero, 'JZ', [ptReg, ptAddress], 'Jumps to given address if value of register is zero'); 111 AddNew(inJumpNotZero, 'JNZ', [ptReg, ptAddress], 'Jumps to given address if value of register is not zero'); 87 112 AddNew(inPush, 'PUSH', [ptReg], 'Pushes value of register to top of the stack.'); 113 AddNew(inPushSize, 'PUSH', [ptDataWidth, ptReg], 'Pushes value of register to top of the stack.'); 88 114 AddNew(inPop, 'POP', [ptReg], 'Pops value of register from top of the stack.'); 89 AddNew(inCall, 'CALL', [ptNumber], 'Calls subroutine at given address. Stores return address to the stack.'); 115 AddNew(inPopSize, 'POP', [ptDataWidth, ptReg], 'Pops value of register from top of the stack.'); 116 AddNew(inCall, 'CALL', [ptAddress], 'Calls subroutine at given address. Stores return address to the stack.'); 117 AddNew(inCallSize, 'CALL', [ptAddressWidth, ptAddress], 'Calls subroutine at given address. Stores return address to the stack.'); 90 118 AddNew(inRet, 'RET', [], 'Return from subroutine. Reads return address from top of the stack to IP register.'); 119 AddNew(inRetSize, 'RET', [ptAddressWidth], 'Return from subroutine. Reads return address from top of the stack to IP register.'); 91 120 AddNew(inAnd, 'AND', [ptReg, ptReg], 'Bitwise AND operation. Result is stored in first parameter.'); 121 AddNew(inAndSize, 'AND', [ptDataWidth, ptReg, ptReg], 'Bitwise AND operation. Result is stored in first parameter.'); 92 122 AddNew(inOr, 'OR', [ptReg, ptReg], 'Bitwise OR operation. Result is stored in first parameter.'); 123 AddNew(inOrSize, 'OR', [ptDataWidth, ptReg, ptReg], 'Bitwise OR operation. Result is stored in first parameter.'); 93 124 AddNew(inXor, 'XOR', [ptReg, ptReg], 'Bitwise XOR operation. Result is stored in first parameter.'); 94 AddNew(inXor, 'SHL', [ptReg, ptReg], 'Shifts all bits to the left in first register by n bits according value of second register.'); 95 AddNew(inXor, 'SHR', [ptReg, ptReg], 'Shifts all bits to the right in first register by n bits according value of second register.'); 125 AddNew(inXorSize, 'XOR', [ptDataWidth, ptReg, ptReg], 'Bitwise XOR operation. Result is stored in first parameter.'); 126 AddNew(inShl, 'SHL', [ptReg, ptReg], 'Shifts all bits to the left in first register by n bits according value of second register.'); 127 AddNew(inShlSize, 'SHL', [ptDataWidth, ptReg, ptReg], 'Shifts all bits to the left in first register by n bits according value of second register.'); 128 AddNew(inShr, 'SHR', [ptReg, ptReg], 'Shifts all bits to the right in first register by n bits according value of second register.'); 129 AddNew(inShrSize, 'SHR', [ptDataWidth, ptReg, ptReg], 'Shifts all bits to the right in first register by n bits according value of second register.'); 96 130 AddNew(inMul, 'MUL', [ptReg, ptReg], 'Multiplies first register with second register value.'); 131 AddNew(inMulSize, 'MUL', [ptDataWidth, ptReg, ptReg], 'Multiplies first register with second register value.'); 97 132 AddNew(inDiv, 'DIV', [ptReg, ptReg], 'Diviedes first register with second register value.'); 133 AddNew(inDivSize, 'DIV', [ptDataWidth, ptReg, ptReg], 'Diviedes first register with second register value.'); 98 134 //AddNew(inMod, 'MOD', [ptReg, ptReg], 'Returns modulo in first registr after division of values.'); 99 AddNew(inJump, 'JP', [pt Number], 'Unconditional absolute jump to defined address.');100 AddNew(inJump Rel, 'JR', [ptNumber], 'Unconditional relative jump to defined address.');101 //AddNew(inLoadIndex, 'LDI', [ptReg, ptRegIndirectIndex], 'Loads value from memory with numeric index to register.');102 //AddNew(inStoreIndex, 'STI', [ptRegIndirectIndex, ptReg], 'Stores value from register to memory with numeric index.');135 AddNew(inJump, 'JP', [ptAddress], 'Unconditional absolute jump to defined address.'); 136 AddNew(inJumpSize, 'JP', [ptAddressWidth, ptAddress], 'Unconditional absolute jump to defined address.'); 137 AddNew(inJumpRel, 'JR', [ptAddress], 'Unconditional relative jump to defined address.'); 138 AddNew(inJumpRelSize, 'JR', [ptAddressWidth, ptAddress], 'Unconditional relative jump to defined address.'); 103 139 //AddNew(inLoadCpu, 'LDC', [], 'Loads value from system register.'); 104 140 //AddNew(inStoreCpu, 'STC', [], 'Stores value to system register.'); … … 107 143 end; 108 144 109 destructor TInstructionSet.Destroy;110 begin111 FreeAndNil(Items);112 inherited;113 end;114 115 145 end. 116 146
Note:
See TracChangeset
for help on using the changeset viewer.