memory-mapped i/o. mapping loose definition: to transform something into a well-understood form...
TRANSCRIPT
Memory-mapped I/O
Mapping
Loose definition: to transform something into a well-understood formExamples: a road map musical notation data mapping
Direct Port Access vs. Memory-mapped Ports
For the most part, Intel-compatible architectures access hardware I/O addresses directlyOther architectures map ports to memory addressesIntel instruction:
in al, 60h
Same instruction with hypothetical mapping:
mov ax, <segment of mapped ports>
mov ds, axmov al, [60h]
So What?
We have to live with what the original architects designedMemory-mapped ports are easier to program for, since any
instruction that can manipulate memory can also manipulate an I/O device
do not require additional instructions
Direct port access is much easier on the system bus is easier to expand and extend
Memory-mapped Memory
Sometimes, an I/O device’s own memory has to be accessible from the CPUIn that case, its memory is wired in to regular RAMThe system bus sends every request (read or write) destined for that memory to the I/O device
Video Card Example
On CGA – VGA (and up) video cards, segments 0B800h and 0A000h are mapped to video memoryAny read from those segments is actually read from the video card’s bufferAny write to those segments is written to the video card’s buffer, and the changes show up the next time the raster scan reads that part of the buffer
Video Card Example (cont.)
Advantage: changes can be made to the video buffer (and, consequently, the screen) using any instruction that can access memory (most of them)Disadvantage: bus latency is increased slightly because for every read or write, the bus has to decide where the request should be sent
The Extra Segment
Wonder no more about what the es register is for – just imagine life without it when dealing with a memory-mapped I/O deviceConsider the following:
mov ax, 0A000hmov es, axmov [es:0], 0
The es register allows you to access portions of memory other than the data segment without destroying the contents of ds
Segment Overrides
Memory is accessed in default segments Direct addressing mode defaults to the data
segment Register-indirect, Base, and Indexed
addressing modes default to the data segment when using bx, si, or di, and to the stack segment when using bp
Base-indexed addressing mode defaults to the data segment
The default segment can be overridden using an es:, ds:, cs:, or ss: prefix
Segment Overrides (cont.)
Examples: mov ax, [es:0] mov bh, [es:di] mov si, [es:bx + si] add [BYTE ss:stackByte], 2 and [BYTE cs:codeByte], -1 cmp [ds:loopCount], cx
By far, the most useful prefix is es:Make darn sure the segments point to meaningful data
Pointer Instructions
lds (load pointer and ds) and les (load pointer and es) load a 32-bit pointer from memory into ds or
es and another register Example:
DATASEGtextScreen DD 0B8000000h
CODESEGles di, [textScreen]
Pointer Instructions (cont.)
lea (load effective address) loads the offset address of a memory
reference into a register Example:
lea bx, [si + TString.buffer] ; Use this
mov bx, si ; Not thisadd bx, TString.buffer