Memory Mapped IO vs Port based IO
CPU connects to multiple external devices like LCD, Hard Disks etc. CPU used for sending and receiving data to/from the devices. Data rate for this transaction might vary from bits to gigabytes .
Process of transaction of data between CPU and Devices, CPU supports multiple ports which are called IO or Input Output. CPU uses these ports for handling multiple devices connected to it.
To access any of the external device we need to map that device at some memory address so that it can be accessed by using some standard command. There are two ways available to map the external devices which are specified below:-
1) Port-mapped IO ( PMIO or isolated IO)
2) Memory-Mapped IO (MMIO)
In case of memory mapped IO , external devices are mapped to the system memory in the same way as ROM and RAM is mapped . It means devices can be accessed in the same way as we access memory in general scenario. Every instruction which can excess memory can be used to access any IO. No need of having any special set of instruction to access these kinds of IO.
In case of memory mapped IO , IO devices use same address bus as memory. The disadvantage of this approach is that entire address bus needs to be decoded for every device. For accessing these IO address bus will require logic gates to decode the address of device being accessed. It increase the cost of hardware.
Port mapped IO use different dedicated address space . This address space can be accessed by special instructions which are completely dedicated to access port mapped IO. For example Intel x86 architecture use IN and OUT commands to Read and Write data respectively .Port mapped IO also use the same address bus but might be needed only few lines to access all the available devices . Which means less hardware will require to decode the address of devices and hence less system cost.
If System has option of Port based IO then its recommended to use Port mapped IO for accessing the devices .This will avoid under utilization of system resources. For example if a system has capacity to access 64K memory and 256 IOs . If we use memory mapped IOs then in that case we need to reserve some memory for IOs and only the left over part can be accessed for general purpose memory. But if you will use port based IO, then you have access to whole 64K memory as well as 256 IOs.
memory mapped IO vs. Port based IO