Search code examples
assemblybit-manipulationendianness

PDP Endian and bit shifts


When you do a bit shift in PDP endian does this operation take a little bit longer than if you where on a little or big endian system?

The reason I ask this question is because it seems like bits going in all directions on a shift, would be hard for a computer to do.

Any ways I have no way to test this because I don't have access to a PDP endian machine. =(


Solution

  • The middle endian format of the PDP11 comes out of the necessity to emulate 32 bit operations on a 16 bit machine. This is done by first storing the high word, then the low word in memory, even though the PDP11 uses little endian for its data. This causes the weird endianess. Though, in practice there isn't really a performance difference. Left shifting an integer stored in memory by one place is still done in three instructions:

    mov #var+2,r0 ; load the address of the low word
    asl (r0)      ; left shift low word
    rol -(r0)     ; left shift high word with carry
    

    If var was stored in little endian, the code would be similar:

    mov #var,r0   ; load address of the low word
    asl (r0)+     ; left shift low word
    rol (r0)      ; left shift high word