From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,255a2533fba89f5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-17 15:05:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!pc-62-31-50-169-cr.blueyonder.co.UK!not-for-mail From: nickroberts@blueyonder.co.uk (Nick Roberts) Newsgroups: comp.lang.ada Subject: Re: Calculate and set Parity Date: Tue, 17 Sep 2002 22:05:50 GMT Organization: AdaOS Message-ID: <3d879cde.85767138@news.cis.dfn.de> References: NNTP-Posting-Host: pc-62-31-50-169-cr.blueyonder.co.uk (62.31.50.169) X-Trace: fu-berlin.de 1032300348 3619724 62.31.50.169 (16 [25716]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:29092 Date: 2002-09-17T22:05:50+00:00 List-Id: On Mon, 16 Sep 2002 18:42:00 +0200, "Sebastian" 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