Input/ Output
I/O vs. Memory mapped I/O
       Heba Abdel-Nabi, Ph.D.
Introduction
          ❑ 8086 uses 16 address bits → A[15:0] to locate an I/O port
          ❑ 64k address space → 65,536 possible I/O ports
          ❑ Data transfer between ports and the processor is done over data bus
          ❑I/O devices serve two main purposes: To communicate with outside world
          and to store data
                                                   Data bus
                    AL
                 AX
                                   I/O          I/O            I/O
                8086
                                         Address bus A[15:0]
                                                                                    Based on Dr. Esam Slides
                                                                                                               2
I/O address mapping
1. Memory-mapped I/O
 • Uses the same shared memory of 8086
 • Reading and writing are similar to memory read/write, e.g. MOV, XCHG
 • Uses same memory read and write signals
2. Isolated I/O (AKA I/O mapped I/O)
• Separate I/O address space, thus, separate I/O read and write signals are needed
• uses dedicated I/O instructions (IN and OUT).
• 64 KB address space, can be any combination of 8- and 16-bit I/O ports
                              FFFFF                                         FFFFF
                                                                                                Range of memory
                                       Memory                                                   addresses
                                       addressing                                     I/O       assigned for I/O transfers
                                       space        FFFF I/O
                                                         addressing                          Memory addressing
                                                                            00000            space
                               00000                0000 space
                                            Isolated I/O                        Memory-mapped I/O
                                                                                                               Based on Dr. Esam Slides
                                                                                                                                          3
I/O address mapping
       I/O mapped I/O                    memory mapped I/O
       Treated as an I/O device (has a   Treated as a memory location (has a
                                                                               Discussed later
       separate 8- or 16- I/O address)   20-bit memory address)
       Given an IOR’ and IOW’ signals    Given an MEMR’ and MEMW’ signals
       Can be accessed by IN/ OUT        Can be accessed using any memory
       instruction                       instruction
       Only work with AL/AX registers    Can work with any register
       Example: Thermometer              Example: Video Graphic arrays (VGA)
                                         card →address of 0B8000H
                                                                                         4
Memory-mapped vs. Isolated I/O
                   Memory Space
              00000
                                               I/O Space
                                        0000
                       1M  8
                                                64K  8
             FFFFF                      FFFF
                                                                Discussed later
                     IO/M = 0                  IO/M = 1
     MOV       AX, DATA                 ; To Read from PORTA
     MOV       DS, AX                   MOV        DX, PORTA
     MOV        BX, OFFSET              IN         AL, DX
     ; To Read from a Memory Location
     MOV        AL, [BX]                ; To Write to PORTB
                                        MOV         DX, PORTB
                                        MOV         AL, VALUE
     ; To Write to a Memory Location
                                        OUT         DX, AL
     MOV         AL, VALUE
     MOV         [BX], AL
                                                                                  5
Input / Output Instructions
• For 8-bit port (data transferred size is 8 bits)
• Two possibilities (8-bit address or 16-bit address)
       IN AL, Port #          OUT Port #, AL → directly
       MOV DX, Port #         MOV DX, Port # → indirectly
       IN AL, DX              OUT DX, AL
• For 16-bit port (data transferred size is 16 bits)
• Two possibilities (8-bit address or 16-bit address)
       IN AX, Port #          OUT Port #, AX → directly
       MOV DX, Port #         MOV DX, Port # → indirectly
       IN AX, DX              OUT DX, AX
                                                            6
Example: thermometer control
again:
in al, 125 ; Data port      Task: Control the thermometer
cmp al, 80                  to maintain the temperature
jae off                     within the range of 60°C to
cmp al,60                   80°C.
jb on                       •If the temperature drops
jmp again                   below 60°C, turn on the flame.
                            •If the temperature rises to or
                            above 80°C, turn off the flame.
off:
mov al,0
out 127,al ; Control port
jmp again
on:
mov al,1
out 127,al
jmp again
Example: VGA
• Print characters ‘a’ and ‘b’ directly without using DOS interrupt
mov ax, 0b800h
mov ds, ax
mov [0000],'a' ; each character takes two bytes
mov [0001],02h ; change the characteristics of the character
mov [0002],'b'
mov [0003],65h