Changeset 182 for branches/virtualcpu4/UDisassembler.pas
- Timestamp:
- Apr 13, 2019, 1:32:32 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UDisassembler.pas
r181 r182 6 6 7 7 uses 8 Classes, SysUtils, UMemory, fgl, UCpu, UInstructionReader ;8 Classes, SysUtils, UMemory, fgl, UCpu, UInstructionReader, Math; 9 9 10 10 type … … 29 29 implementation 30 30 31 const 32 SignText: array[TValueSign] of string = ('-', '', '+'); 33 34 function SignedIntToHex(Value: Int64; Digits: Byte): string; 35 begin 36 Result := SignText[Sign(Value)] + IntToHex(Abs(Value), Digits); 37 end; 38 31 39 { TDisassembler } 32 40 … … 46 54 MemorySize := MemSize(Cpu.Memory); 47 55 while IP < MemorySize do begin 48 if DataSizePrefix <> bwNone then begin 49 DataSizeLast := DataSize; 50 DataSize := DataSizePrefix; 51 DataSizePrefix := bwNone; 52 end; 53 if AddrSizePrefix <> bwNone then begin 54 AddrSizeLast := AddrSize; 55 AddrSize := AddrSizePrefix; 56 AddrSizePrefix := bwNone; 57 end; 56 Prefix := False; 58 57 Opcode := Read8; 59 58 if Opcode < Integer(High(TOpcode)) then begin 59 Prefix := OpcodeDef[TOpcode(Opcode)].Prefix; 60 60 case TOpcode(Opcode) of 61 opDataPrefix8: DataSize Prefix:= bw8;62 opDataPrefix16: DataSize Prefix:= bw16;63 opDataPrefix32: DataSize Prefix:= bw32;64 opDataPrefix64: DataSize Prefix:= bw64;65 opAddrPrefix8: AddrSize Prefix:= bw8;66 opAddrPrefix16: AddrSize Prefix:= bw16;67 opAddrPrefix32: AddrSize Prefix:= bw32;68 opAddrPrefix64: AddrSize Prefix:= bw64;61 opDataPrefix8: DataSize := bw8; 62 opDataPrefix16: DataSize := bw16; 63 opDataPrefix32: DataSize := bw32; 64 opDataPrefix64: DataSize := bw64; 65 opAddrPrefix8: AddrSize := bw8; 66 opAddrPrefix16: AddrSize := bw16; 67 opAddrPrefix32: AddrSize := bw32; 68 opAddrPrefix64: AddrSize := bw64; 69 69 end; 70 70 Line := TDisassemblerLine.Create; … … 90 90 prAddrRel: begin 91 91 AddressRel := ReadAddressSigned; 92 Line.Opcode := Line.Opcode + ' ' + IntToHex( AddressRel, BitWidthBytes[AddrSize] * 2);93 Line.Instruction := Line.Instruction + ' $' + IntToHex(AddressRel, BitWidthBytes[AddrSize] * 2);92 Line.Opcode := Line.Opcode + ' ' + IntToHex(QWord(AddressRel), BitWidthBytes[AddrSize] * 2); 93 Line.Instruction := Line.Instruction + ' $' + SignedIntToHex(AddressRel, BitWidthBytes[AddrSize] * 2); 94 94 end; 95 95 end; … … 113 113 AddressRel := ReadAddressSigned; 114 114 Line.Opcode := Line.Opcode + ' ' + IntToHex(AddressRel, BitWidthBytes[AddrSize] * 2); 115 Line.Instruction := Line.Instruction + ', $' + IntToHex(AddressRel, BitWidthBytes[AddrSize] * 2);115 Line.Instruction := Line.Instruction + ', $' + SignedIntToHex(AddressRel, BitWidthBytes[AddrSize] * 2); 116 116 end; 117 117 end; … … 134 134 prAddrRel: begin 135 135 AddressRel := ReadAddressSigned; 136 Line.Opcode := Line.Opcode + ' ' + IntToHex( AddressRel, BitWidthBytes[AddrSize] * 2);137 Line.Instruction := Line.Instruction + ', $' + IntToHex(AddressRel, BitWidthBytes[AddrSize] * 2);136 Line.Opcode := Line.Opcode + ' ' + IntToHex(QWord(AddressRel), BitWidthBytes[AddrSize] * 2); 137 Line.Instruction := Line.Instruction + ', $' + SignedIntToHex(AddressRel, BitWidthBytes[AddrSize] * 2); 138 138 end; 139 139 end; … … 147 147 } 148 148 end; 149 if DataSizeLast <> bwNone then begin 150 DataSize := DataSizeLast; 151 DataSizeLast := bwNone; 152 end; 153 if AddrSizeLast <> bwNone then begin 154 AddrSize := AddrSizeLast; 155 AddrSizeLast := bwNone; 149 if not Prefix then begin 150 DataSize := DataSizeBase; 151 AddrSize := AddrSizeBase; 156 152 end; 157 153 end;
Note:
See TracChangeset
for help on using the changeset viewer.