2.8 Endianness.
The instruction is also known as “NSA^22 instruction” due to rumors:
This branch of cryptography is fast-paced and very politically charged. Most designs
are secret; a majority of military encryptions systems in use today are based on LFSRs. In
fact, most Cray computers (Cray 1, Cray X-MP, Cray Y-MP) have a rather curious instruction
generallyknownas“populationcount.” Itcountsthe1bitsinaregisterandcanbeusedboth
to efficiently calculate the Hamming distance between two binary wordsand to implement a
vectorized version of a LFSR. I’ve heard this called the canonical NSA instruction, demanded
by almost all computer contracts.
[Bruce Schneier,Applied Cryptography, (John Wiley & Sons, 1994)]
2.8 Endianness
The endianness is a way of representing values in memory.
2.8.1 Big-endian.
The0x12345678value is represented in memory as:
address in memory byte value
+0 0x12
+1 0x34
+2 0x56
+3 0x78
Big-endian CPUs include Motorola 68k, IBM POWER.
2.8.2 Little-endian.
The0x12345678value is represented in memory as:
address in memory byte value
+0 0x78
+1 0x56
+2 0x34
+3 0x12
Little-endian CPUs include Intel x86.
2.8.3 Example
Let’s take big-endian MIPS Linux installed and ready in QEMU^23.
And let’s compile this simple example:
#include <stdio.h>
int main()
{
int v, i;
v=123;
printf ("%02X %02X %02X %02X\n",
*(char*)&v,
*(((char*)&v)+1),
*(((char*)&v)+2),
(^22) National Security Agency
(^23) Available for download here:http://go.yurichev.com/17008