"Processor register" and "IO register"

I was wondering if processor registers and IO registers are the same concept?

Are they registers in CPU or in some IO devices?

I picked up IO registers from this Super User question.


Solution 1:

Processor registers - generally, something to do with any operation that the CPU does must be in one of its registers.

For example, look at this. It's the various forms of the Intel x86 ADD instruction. You'll notice that you can add two registers together, or add a register together with the contents of a memory location ("accumulator" is just another register, "immediate" just means the data is in the memory location directly, or "immediately" after the actual ADD opcode). There is no ADD mem,mem.

RISC CPU's such as ARM are even less flexible. Data from memory must always be copied to a register as a separate operation before the CPU can do anything like ADD, SUB, etc. to it. They have many more registers to make up for this.

I/O registers - generally, something to do with any operation that an I/O chipset or device does must be in one of its registers.

For example, look at this. It's detail about the standard VGA "CRTC registers." Of particular interest is the "Start Address High" and "Start Address Low" registers. The values in these registers tell the VGA where to begin reading memory to render a display.

There's many ways to make I/O registers accessible from a CPU. Usually it is not like processor registers above. Various methods include:

  • One way is creating the I/O device so it responds the same way on a hardware level as RAM, but only at certain addresses. Reads/writes to those addresses don't go to RAM, but the I/O device. I/O devices may then make their registers accessible at certain addresses. The CPU then reads or writes the registers using the same ones it does for RAM. Very common on 8-bit and ARM architectures.
  • x86 does have special IN and OUT instructions for I/O. These specify addresses but not ones that RAM can be connected to. I/O devices may connect to these addresses (usually called "ports", not to be confused with TCP ports) and make their registers accessible this way.

Continuing with the example of the VGA CRTC registers above, with how I explained "I/O ports" above you are now armed with the knowledge to understand this and understand that by issuing specific OUT instructions the CPU then modifies the value in the VGA's I/O register, which is retained and used by the VGA chipset.

Not all I/O devices have registers. Some are really simple and just need some sort of signal to do their thing, and also "reading" the device just reports a current state. The old PC "game port" is an example. There's really no storage of data going on so it might not be technically correct to call it a register. Most technical documentation won't make this distinction, though.

Solution 2:

You can compare the concept of an I/O register to a generic hardware register, since a register is an arbitrary term used to refer to a digital storage area. A register can act as an accumulator, hold execution information, provide an input-output buffer between devices, etc. This also means that a processor register is just a type of hardware register.

An I/O register, then, is also an abstraction of a register - it holds intermediate data moving between components. Processors do not have specific I/O registers but rather, various generic registers which can accomplish the same task (which are used, for example, when the system uses memory mapped I/O). These are used to provide a common interface bus between the CPU and the memory of the system, but in the case of MMIO, allow access to external devices' memory off of the actual address bus.

How would a programmer actually do this? They would need to determine how the external device is mapped onto the address bus of the system, and then use one of the various x86 registers to store the address (in an index/pointer register). This register could then be used (with machine instructions) to transfer data to/from another register in the processor to a register on the device.

If the CPU does not support MMIO (or the programmer decides not to use it), then in the case of x86 there can also exist special instructions for I/O from a port (which is essentially another bus). These instructions (IN and OUT) work similar to the MOV instruction - they even use the same processor registers. The only difference is what the address in the index/pointer registers means (since those registers use a different I/O address map).


This is why I say that I/O registers are an abstraction of any other CPU register - they are one in the same thing. The data still moves in and out of the processor into the same registers, whether or not they are used for intermediate results, data transfer to/from the RAM, or accessing external hardware.

Depending on the motherboard layout, a CPU may access an external devices' memory through the actual address bus itself, or another bus connected to a port on the CPU. However, all of this is usually governed by the motherboard's northbridge for memory access, and southbridge for peripheral access (e.g. video cards, mouse/keyboard).

Finally, if you're familiar with the concept of DMA, external peripherals themselves can have registers designated specifically for I/O purposes from the computer's RAM. Do note that DMA basically circumvents any CPU intervention, so the concept of a processor register would not be applicable here.


Final word: Every device in your computer has a register of some kind, since no device is connected directly to the CPU - and if it was, then you would be wasting CPU clock cycles keeping the data on the bus until the device had enough time to use it (the CPU usually has the fastest clock in any system). This is just one reason why devices need a place to store data before they can work with it - and that is essentially all a register is.

Solution 3:

Conceptually I/O registers and Processor registers are the same thing. They both are data holding units of storage for processing operations.

The difference is one of locality. I/O registers and CPU registers are all part of the same family; Hardware Registers. CPU registers live in the CPU, I/O registers live outside the CPU on your I/O devices own digital processors.

For detailed information: Hardware Registers, explains hardware registers in general, making mention of their different kinds.