Registers use some type of electronic cycles called flip-flops, a flip-flop is a cycle that stores 0 or 1 and keeps it stored. An N size register is a block of N flip-flops. The flip-flop looks like this:
- clock: is a trigger that when it activated the data is passed, so no data, 0 or 1, is stored by ascendent. It's controlled by the control unit in the CPU.
- input: is a input for 1 bit, tiny wire, stores either 0 or 1 in the flip-flop.
- output: is output where you can read the data.
In a 32 bit register, 32 of these are aligned in one block with 32 bit input and 32 bit output:
notice, in this register there is no sub-registers, like eax
, ax
, ah
, al
. I guess Intel guys had to use 4 bit clock rather than 1 as:
- First clock, activates all the 32 bit flip-flops,
eax
. - Second clock, activates only the lower 16 bit flip-flops,
ax
. - Third clock, activates only the second 8 bit,
ah
. - Fourth clock, activates only the first 8 bit,
al
.
something like (8 FF, 8 flip-flops, and the dots means the line is connected there):
now when the processor decodes the instructions, it can tell which instruction you want and which register you target, which clock to trigger, using the opcode of the instruction:
[b0] ff mov $0xff, %al
[b4] ff mov $0xff, %ah
[66 b8] ff ff mov $0xffff, %ax
[b8] ff ff ff ff mov $0xffffffff, %eax
The realty might be different, but the principle is the same. You can read more about this stuff in any logic-design or computer architecture book, but you don't need to it to start program in assembly, but it will help you to understand how stuff works.