You seem not to have understood how the CPU and the bus are working:
As you knows network i/o is based on nic interrupt.
An interrupt is a mechanism which is starting a short program whenever the hardware (for example the network card) requests the CPU to do so.
An interrupt only starts this short program; it does nothing else. It also does not transfer any kind of data.
Another mechanism shown on your image is DMA. Using DMA a hardware component (such as the network card) can directly read data from the RAM or write data to the RAM. The network card obviously uses this mechanism to copy network data to the RAM and to send data which is stored in the RAM.
However, if we want to send data to the network, we first have to tell the network card that there is data to be sent at all before the network card can access the RAM using DMA. The same is true when we want to initialize the network card.
So using DMA only, we cannot tell the network card that there is data to be sent. Initializing the network card when the computer is started is also not possible. Interrupts will also not help us because interrupts are initiated by the network card and not by the software. We need a third mechanism to access the network card.
so why do we need assembly instructions in and out to get data from nic register directly?
When using x86 CPUs, the in
and out
instructions are used to directly read and write data to some hardware component.
Indeed hardware can be attached to the CPU in a way that it is accessed in the same way RAM is accessed: For example using mov
instructions. The memory of the graphics card is accessed this way. There are also CPUs (like ARM CPUs which are common in cell phones) that access all hardware the same way RAM is accessed. (Such CPUs don’t have in
or out
instructions.)
In PC-compatible computers however, hardware is typically attached in a way that it must be accessed using in
and out
instructions.
3
solved why do we need assembly instructions in and out? [closed]