From: nickroberts@blueyonder.co.uk (Nick Roberts)
Subject: Re: Calculate and set Parity
Date: Tue, 17 Sep 2002 22:05:50 GMT
Date: 2002-09-17T22:05:50+00:00 [thread overview]
Message-ID: <3d879cde.85767138@news.cis.dfn.de> (raw)
In-Reply-To: am518n$qbq$1@newstoo.ericsson.se
On Mon, 16 Sep 2002 18:42:00 +0200, "Sebastian"
<sebastian.madunic@avionics.saab.se> strongly typed:
>Hi,
>
>I need a subroutine that calculates the parity of a record type with the
>size of 16 bits. Is there some nice way
>to do this? I currently have a solution were I use Unchecked_Conversion to
>convert my variable to an
>array booleans, then I calculate every true etc. Is there some way to do
>this without using Unchecked_Conversion.
From the Intel documentation:
PF (bit 2) Parity flag. Set if the least-significant byte of the result
contains an even number of 1 bits; cleared otherwise.
This flag is set by any arithmetic instruction.
Assuming your 16-bit number is in DataHi:DataLo, the following code on any
IA machine should leave the answer in DL:
MOV AL, DataLo ; load a byte
AND AL, AL ; set PF
LAHF ; load flags byte
SHR AH, 2 ; shift PF into bit 0
AND AH, 1 ; mask off all other bits
MOV DL, AH ; result into DL
MOV AL, DataHi
AND AL, AL
LAHF
SHR AH, 2
AND AH, 1
XOR DL, AH ; parities must be XORed to get cumulative result
I think most other architectures provide something similar.
I'll leave the details as an exercise ;-) HTH
--
Nick Roberts
Per Ardua ad Disastra
next prev parent reply other threads:[~2002-09-17 22:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-16 16:42 Calculate and set Parity Sebastian
2002-09-16 18:14 ` Stephen Leake
2002-09-16 18:58 ` Jeffrey Carter
2002-09-16 19:51 ` tmoran
2002-09-17 1:36 ` tmoran
2002-09-17 22:05 ` Nick Roberts [this message]
2002-09-17 23:23 ` tmoran
2002-09-18 0:17 ` tmoran
2002-09-18 20:25 ` Nick Roberts
2002-09-18 2:52 ` SteveD
2002-09-18 18:29 ` Parity using 'Write, was " tmoran
2002-09-18 18:47 ` David C. Hoos
2002-09-18 22:17 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox