Search code examples
assemblyiox86x86-16

IN/OUT access to addresses above 2^16?


How can I load/store data to the periphery which address is bigger than 216 with IN/OUT instructions.

When I use IN/OUT instruction, lets say OUT DX, AL, I know that the segment register of DX is not used so I can access only the first 216 addresses (because DX is 16 bits wide).

One of my devices is on the address 18000h. How can I reach it? The memory/IO space overlaps (the M/IO pin is not used), so is it ok to say something like

MOV BX, 18000h
MOV [BX], AL

Solution

  • You can't with IN or OUT instruction!

    The x86 processor supports an I/O address space that contains up to 65,536 8-bit I/O ports.

    From Intel datasheet:

    The processor permits applications to access I/O ports in either of two ways:

    • Through a separate I/O address space
    • Through memory-mapped I/O

    Accessing I/O ports through the I/O address space is handled through a set of I/O instructions and a special I/O protection mechanism. Accessing I/O ports through memory-mapped I/O is handled with the processors general-purpose move and string instructions, with protection provided through segmentation or paging. I/O ports can be mapped so that they appear in the I/O address space or the physicalmemory address space (memory mapped I/O) or both.