A compiler takes a high level language like C or C++ or whatever and breaks it down into assembly language instructions.
For instance
Code:
x = 2;
x++;
if (x < 5)
{
x+=2;
}
else
{
x-=2;
}
x = x * 2;
Would generate this assembly (approximately, MIPS assembly)
Code:
ADDIU A0, R0, 2
ADDIU A0, A0, 1
ADDIU A1, A0, 0
SUBIU A1, A1, 5
BGEZ A1, label1
ADDIU A0, A0, 2
J label2
label1:
SUBIU A0, A0, 2
label2:
MULIU A0, A0, 2
SB A0, x
For reference, SB = Store Byte, ADDIU = Add Immediate Unsigned, BGEZ = Branch on Greater Than or Equal to Zero, J = Jump. Register R0 always contains zero.
Values are assigned to registers by way of adding the contents of R0 and that value, and storing the contents in the destination register.
Anyway, those instructions all contain a binary representation...
ADDIU might specify a 6-binary bit code, maybe 000100.
Lets say we have the instruction ADDIU A0, R0, 2
We build the machine code:
ADDIU = 000100
A0 = 00010
R0 = 00000
"2" = 0000000000000010
On a 32 bit machine, this instruction is represented as (actually its in reverse, but for illustration we won't reverse it):
Code:
00010000010000000000000000000010
ADDIU A0 R0 Immediate
In hex:
10400002
This is the code that is sent to the CPU to be executed.