Ignore:
Timestamp:
Apr 13, 2019, 1:32:32 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Allow to use multiple prefix instructions in row.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/UDisassembler.pas

    r181 r182  
    66
    77uses
    8   Classes, SysUtils, UMemory, fgl, UCpu, UInstructionReader;
     8  Classes, SysUtils, UMemory, fgl, UCpu, UInstructionReader, Math;
    99
    1010type
     
    2929implementation
    3030
     31const
     32  SignText: array[TValueSign] of string = ('-', '', '+');
     33
     34function SignedIntToHex(Value: Int64; Digits: Byte): string;
     35begin
     36  Result := SignText[Sign(Value)] + IntToHex(Abs(Value), Digits);
     37end;
     38
    3139{ TDisassembler }
    3240
     
    4654  MemorySize := MemSize(Cpu.Memory);
    4755  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;
    5857    Opcode := Read8;
    5958    if Opcode < Integer(High(TOpcode)) then begin
     59      Prefix := OpcodeDef[TOpcode(Opcode)].Prefix;
    6060      case TOpcode(Opcode) of
    61         opDataPrefix8: DataSizePrefix := bw8;
    62         opDataPrefix16: DataSizePrefix := bw16;
    63         opDataPrefix32: DataSizePrefix := bw32;
    64         opDataPrefix64: DataSizePrefix := bw64;
    65         opAddrPrefix8: AddrSizePrefix := bw8;
    66         opAddrPrefix16: AddrSizePrefix := bw16;
    67         opAddrPrefix32: AddrSizePrefix := bw32;
    68         opAddrPrefix64: AddrSizePrefix := 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;
    6969      end;
    7070      Line := TDisassemblerLine.Create;
     
    9090        prAddrRel: begin
    9191          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);
    9494        end;
    9595      end;
     
    113113          AddressRel := ReadAddressSigned;
    114114          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);
    116116        end;
    117117      end;
     
    134134        prAddrRel: begin
    135135          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);
    138138        end;
    139139      end;
     
    147147      }
    148148    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;
    156152    end;
    157153  end;
Note: See TracChangeset for help on using the changeset viewer.