Changeset 181 for branches/virtualcpu4/UInstructionWriter.pas
- Timestamp:
- Apr 13, 2019, 12:03:31 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UInstructionWriter.pas
r180 r181 6 6 7 7 uses 8 Classes, SysUtils, UCpu , UMemory, fgl;8 Classes, SysUtils, UCpu; 9 9 10 10 type … … 31 31 procedure Write64(Value: QWord); 32 32 procedure WriteAddress(Value: TAddress); 33 procedure WriteAddressSigned(Value: TAddressSigned); 33 procedure WriteAddressSigned(Value: TAddressSigned); inline; 34 34 procedure WriteData(Value: QWord); 35 35 procedure WriteString(Text: string); … … 64 64 end; 65 65 66 { TAssembler }67 68 TAssembler = class69 Source: TStringList;70 Dest: array of Byte;71 procedure Compile;72 end;73 74 TDisassemblerLine = class75 Address: Integer;76 Opcode: string;77 Instruction: string;78 end;79 80 { TDisassembler }81 82 TDisassembler = class83 Memory: TMemoryPos;84 Output: TFPGObjectList<TDisassemblerLine>;85 procedure Process;86 constructor Create;87 destructor Destroy; override;88 end;89 90 const91 OpcodeName: array[TOpcode] of string = ('NOP', 'HALT', 'LD', 'LDI', 'JP', 'JPZ',92 'JPNZ', 'JR', 'JRZ', 'JRNZ', 'NEG', 'CLR', 'LDM', 'STM', 'EX', 'PUSH', 'POP',93 'CALL', 'RET', 'ADD', 'ADDI', 'SUB', 'SUBI', 'INC', 'DEC', 'IN', 'OUT',94 'SHL', 'SHR', 'DP8', 'DP16', 'DP32', 'DP64', 'DS', 'AS', 'TEST', 'AND', 'OR',95 'XOR', 'LDDR', 'LDIR', 'MUL', 'DIV', 'MOD', 'AP8', 'AP16', 'AP32', 'AP64');96 66 97 67 implementation 98 99 { TDisassembler }100 101 procedure TDisassembler.Process;102 var103 Opcode: Byte;104 Line: TDisassemblerLine;105 begin106 Output.Clear;107 Memory.Position := Memory.Data;108 109 while Memory.Position < Memory.Data + Memory.Size do begin110 Opcode := Memory.ReadByte;111 if Opcode < Integer(High(TOpcode)) then begin112 Line := TDisassemblerLine.Create;113 Line.Address := Memory.Position - Memory.Data;114 Line.Opcode := IntToHex(Opcode, 2);115 Line.Instruction := OpcodeName[TOpcode(Opcode)];116 Output.Add(Line);117 end;118 end;119 end;120 121 constructor TDisassembler.Create;122 begin123 Output := TFPGObjectList<TDisassemblerLine>.Create;124 Memory := TMemoryPos.Create;125 end;126 127 destructor TDisassembler.Destroy;128 begin129 Memory.Free;130 Output.Free;131 inherited Destroy;132 end;133 134 { TAssembler }135 136 procedure TAssembler.Compile;137 begin138 139 end;140 68 141 69 { TInstructionWriter }
Note:
See TracChangeset
for help on using the changeset viewer.