Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Algorithmen (https://www.delphipraxis.net/28-library-algorithmen/)
-   -   Delphi Parität [ASM] (https://www.delphipraxis.net/17026-paritaet-%5Basm%5D.html)

neolithos 27. Feb 2004 08:04


Parität [ASM]
 
Delphi-Quellcode:
function CalcEvenParity(dwData : Cardinal) : Integer;
// Gibt das Bit zurück um, welches eine Zahl ergänzt werden muss um auf die gerade Parität
// zu kommen
asm
  test eax, eax
  jpo @@1
  mov eax, 0 // even Parität also muss eine 0 ergänzt werden
  ret
@@1:
  mov eax, 1 // odd Parität also muss eine 1 ergänzt werden
end;
Delphi-Quellcode:
function CalcOddParity(dwData : Cardinal) : Integer;
// Gibt das Bit zurück um, welches eine Zahl ergänzt werden muss um auf die ungerade Parität
// zu kommen
asm
  test eax, eax
  jpe @@1
  mov eax, 0 // even Parität also muss eine 0 ergänzt werden
  ret
@@1:
  mov eax, 1 // odd Parität also muss eine 1 ergänzt werden
end;

neolithos 27. Feb 2004 08:05

Re: Parität [ASM]
 
Für alle Delphi 8 User:

Delphi-Quellcode:
function CalcEvenParity(dwData : Cardinal) : Integer;
// Gibt das Bit zurück um, welches eine Zahl ergänzt werden muss um auf die gerade Parität
// zu kommen
var dwParity : Cardinal;
    i : Integer;
begin
  dwParity := 0;
  for i := 0 to 31 do
      begin
        dwParity := dwParity xor (dwData and 1);
        bData := bData shr 1;
      end;
  Result := dwParity;
end;
Delphi-Quellcode:
function CalcOddParity(dwData : Cardinal) : Integer;
// Gibt das Bit zurück um, welches eine Zahl ergänzt werden muss um auf die ungerade Parität
// zu kommen
var dwParity : Cardinal;
    i : Integer;
begin
  dwParity := 0;
  for i := 0 to 31 do
      begin
        dwParity := dwParity xor (dwData and 1);
        bData := bData shr 1;
      end;
  Result := not dwParity and 1;
end;

neolithos 27. Feb 2004 08:29

Re: Parität [ASM]
 
Delphi-Quellcode:
function CheckXOr(var buf; iSize : Integer) : Integer;
// Errechnet die gerade Parität von 8 Bit-Blöcken
asm
  mov ecx, edx // Size in Counter
  xor edx, edx // edx = 0
  test ecx, ecx
  jz @@2     // Size = 0 -> Exit

@@1:
  xor dl, [eax + ecx - 1]
  loop @@1

@@2:
  mov eax, edx
end;

flomei 21. Sep 2004 16:34

Re: Parität [ASM]
 
Zitat:

Zitat von neolithos
Diese ist fuer das 32Bit Delphi. Und gibt zurueck, dass es sich um gerade Paritaet handelt.
Delphi-Quellcode:
function Parity(Value: Cardinal): Boolean;
asm
   TEST EAX, EAX
   SETP AL
end;
Das gleiche bloss fuer viele Pascal/Delphi Compiler
Delphi-Quellcode:
function Parity(Value: Cardinal): Boolean;
begin
  Value := (Value shr 16) xor (Value and $FFFF);
  Value := (Value shr 8) xor (Value and $00FF);
  Value := (Value shr 4) xor (Value and $000F);
  Value := (Value shr 2) xor (Value and $0003);
  Value := (Value shr 1) xor (Value and $0001);
  Result := Value <> 0;
end;

MfG Florian :hi:


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz