Einzelnen Beitrag anzeigen

Olli
(Gast)

n/a Beiträge
 
#4

Re: Fehler beim Byte-Swap mit Assembler in Delphi

  Alt 1. Jul 2005, 22:56
Falls du es noch für ULONGLONG (LARGE_INTEGER/ULARGE_INTEGER) brauchst:

Delphi-Quellcode:
(* Own function to swap bytes in 64bit values

  The RtlUlonglongByteSwap routine converts a ULONGLONG from
   little-endian to big-endian, and vice versa. *)

function RtlUlonglongByteSwap(Source:ULONGLONG):ULONGLONG;
asm
  mov EAX, [ESP+0Ch] // Get the high part of the ULONGLONG into EAX
  mov EDX, [ESP+08h] // Get the low part of the ULONGLONG into EDX
  // This is not written as mnemonics to be compatible with D4!
  db 0Fh, 0C8h // "bswap EAX" can only be executed on 486+!!!
  db 0Fh, 0CAh // "bswap EDX" can only be executed on 486+!!!
  // High part returns in EDX, low part in EAX
end;
Ach Quark ... für die Vollständigkeit noch 16bit-Werte:

Delphi-Quellcode:
(* Own function to swap bytes in 16bit values

  The RtlUshortByteSwap routine converts a USHORT from
   little-endian to big-endian, and vice versa. *)

function RtlUshortByteSwap(Source:USHORT):USHORT;
asm
  rol AX, 08h
end;
Ach ja, der Code ist JEDI-kompatibel unter MPL. Aber da ich der Urheber bin ...
  Mit Zitat antworten Zitat