How to count zeros in registers?

On 01/12/2005 the venerable Jim Thompson etched in runes:

Not neccessarily, because that requires access to the carry bit which has been shifted out. My method only looks at the contents of the register and thus can be done in a high level language such as 'C' which has no knowledge of the carry bit.

--
John B
Reply to
John B
Loading thread data ...

what output do you want?

--

Bye.
   Jasen
Reply to
Jasen Betts

Clever, but doesn't that yield the total number of '1's rather than the number of leading zeros?

/* return the number of leading zeros, 0x08 if all zeros, for 0

Reply to
Spehro Pefhany

Yes... and I think the original poster has that luxury, I concur that this looks a lot like homework. So what he's needing to do is draw a K-map. I just wanted to steer him in the right direction without doing it for him

By the way, code to draw K-maps is not too hard to write. Collecting minterms isn't too far beyond that. Reducing 'em isn't too far beyond that. Having tools like that cuts the time down, bringing such luxuries into reach of even the humble compiler user

Wood

Reply to
Woody Brison

I can still do 'em by hand but, now-a-days, I use KarnaughMap v4.4.5, by Russell Sasamori...

formatting link

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

In article , Rich Grise wrote: [...]

If there are only 8 bits to worry about:

X := (X and $55) + ((X shr 1) and $55); X := (X and $33) + ((X shr 2) and $33); X := (X and $07) + ((X shr 4) and $07);

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

On 01/12/2005 the venerable Jim Thompson etched in runes:

. .

I use three programming languages 'C', solder and unprintable comments when the other two fail.

--
John B
Reply to
John B

A lookup table is the fastest way to do this, and most other bit counting/swapping/noticing/priority kinds of things, if you have the memory.

--- Regards, Bob Monsen

The question of the ultimate foundations and the ultimate meaning of mathematics remains open; we do not know in what direction it will find its final solution or even whether a final objective answer can be expected at all. "Mathematizing" may well be a creative activity of man, like language or music, of primary originality, whose historical decisions defy complete objective rationalization.

- Hermann Weyl in 1944

Reply to
Bob Monsen

In article , Spehro Pefhany wrote: [...]

Yes. I saw a mension of counting the total number of bits elsewhere. I guess I didn't pay careful enough attention to which I was responding to.

It should be:

TEMP := X; Y := 0;

if (TEMP and $F0) = 0 then begin TEMP := TEMP shl 4; Y := Y + 4; end;

if (TEMP and $C0) = 0 then begin TEMP := TEMP shl 2; Y := Y + 2; end;

if (TEMP and $80) = 0 then begin TEMP := TEMP shl 1; Y := Y + 1; end; With a little work this could be reduced to a loop. Note that you get a normalized output as well as the shifts needed to normalize.

How about: for (i=0, m=0x80; (i

Reply to
Ken Smith

...

Assuming a math co-processor on the system, by far the simplest, fastest, and most obtuse way is to convert to floating point and figure out what to do with the exponent. (IEEE floating point values are stored as a mantissa between .5 and 1 raised to an exponent of 2.)

Reply to
Mike Young

"Ken Smith" schreef in bericht news:dmob8s$dsm$ snipped-for-privacy@blue.rahul.net...

Reply to
Frank Bemelman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.