Re: Variadic functions calling variadic functions with the argument list, HLL bit shifts on LE processors

From: Gordon Burditt (gordonb.zmh81_at_burditt.org)
Date: 03/03/05


Date: 03 Mar 2005 21:36:09 GMT


>About Little-Endian, I'm aware many chips have big and little-endian
>modes, eg SPARC, PowerPC, Itanium, but the Intel x86 chips are
>little-endian, and as well the low order bytes of the word are aliased
>to specific sections of the register, and there are zillions of those
>things sitting around.

So what? Write your code so it doesn't matter what endian the
processor is.

>About Little-Endian and shift, I'm trying to think of an example. Say
>I have a 32 bit unsigned word with each byte being an encoded symbol.
>
>0x AA BB CC DD

It's a VALUE. Quit putting those stupid spaces in there.

>If a certain bit in another register is set, I want to shift that
>right.
>
>0x 00 AA BB CC
>
>Then, regardless of whether CC or DD is in the low byte, I test that
>byte for a bit. If it's set, there's this processing, and then what's
>left is conditionally shifted 16 bits.
>
>0x 00 00 00 AA
>or
>0x 00 00 AA BB
>
>Now, all I'm interested in is the low byte there. So, on the x86
>register eax, say, it is as so
>
>-------eax -----
>--eah--- ---eal---
> -ah- -al-
>AA 00 00 00
>
>then, if I want to move that byte off then I think it has to go onto ah
>or al to be moved into a memory location at a byte offset.

A one-byte value does not have byte order.

>So, I'm
>causing myself grief about flipping the original number to 0x DD CC BB
>AA and shifting it the other way, for the Little-Endian case, because
>those bit tests (and + jnz, I suppose) or moves work off of the byte
>size register aliases off of the x86.

What the heck are you talking about? You think flipping the order
is FASTER? It's not. You think flipping the order and shifting gives
you the same answer? It doesn't. Reversing the order of BYTES does not
reverse the order of BITS.

If you're doing a 32-bit shift, IT DOES A 32-BIT SHIFT. Stupid register
aliases have nothing to do with it. By definition, AL refers to the low-order
byte of EAX on an Intel processor, and has nothing to do with whether the
processor is big-endian or little-endian. If you're doing a 32-bit bitwise
AND, it does a full 32-bit bitwise AND. byte size register aliases have
nothing to do with it.

>Then I get to thinking about my near complete lack of knowledge of how
>the Big-Endian processor best or most happily works with moving bytes
>off of the register into memory, using C. What are some good examples
>of useful knowledge from C of the byte order of the processor, and how
>it loads bytes to and from memory, or casting int & 0xFF to byte?

When you use C, you're not supposed to CARE about the endianness, or lack
thereof, of the processor.

If it wants to load a 32-bit value out of memory, IT LOADS A 32-bit VALUE
OUT OF MEMORY. There are no speed issues about which end is done first,
so you shouldn't care. The bytes wind up in the right places in the register
based on endianness or lack thereof.

>So, I should probably go compile some shifts and step through their
>disassembly on the Pentium, to perhaps enhance but hopefully diminish
>my deep personal confusion about low-voltage electronics.

The specification of the software interface has nothing to do with whether
the Pentium uses low-voltage electronics or quantum warp fields or orbital
mind-control lasers. It still works the same.

                                                        Gordon L. Burditt



Relevant Pages