Einzelnen Beitrag anzeigen

Amateurprofi
Online

Registriert seit: 17. Nov 2005
Ort: Hamburg
1.041 Beiträge
 
Delphi XE2 Professional
 
#17

AW: Konvertierung von BigEndian-Werten

  Alt 26. Jul 2012, 00:43
Oder so.
Der Compiler wird sich die richtige Funktion selber suchen.

Delphi-Quellcode:
FUNCTION ChangeEndian(value:Word):Word; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   {$ENDIF}
   XCHG al,ah
end;

FUNCTION ChangeEndian(value:DWord):DWord; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   {$ENDIF}
   bswap eax
end;

FUNCTION ChangeEndian(const value:UInt64):UInt64; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   bswap rax
   {$ELSE}
   mov edx,[esp+8]
   mov eax,[esp+12]
   bswap eax
   bswap edx
   {$ENDIF}
end;

FUNCTION ChangeEndian(value:SmallInt):SmallInt; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   {$ENDIF}
   XCHG al,ah
end;

FUNCTION ChangeEndian(value:Integer):Integer; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   {$ENDIF}
   bswap eax
end;

FUNCTION ChangeEndian(const value:Int64):Int64; overload;
asm
   {$IFDEF CPUX64}
   mov rax,rcx
   bswap rax
   {$ELSE}
   mov edx,[esp+8]
   mov eax,[esp+12]
   bswap eax
   bswap edx
   {$ENDIF}
end;
Gruß, Klaus
Die Titanic wurde von Profis gebaut,
die Arche Noah von einem Amateur.
... Und dieser Beitrag vom Amateurprofi....
  Mit Zitat antworten Zitat