![Page 1: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/1.jpg)
Memory-mapped I/O
![Page 2: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/2.jpg)
Mapping
Loose definition: to transform something into a well-understood formExamples: a road map musical notation data mapping
![Page 3: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/3.jpg)
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]
![Page 4: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/4.jpg)
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
![Page 5: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/5.jpg)
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
![Page 6: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/6.jpg)
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
![Page 7: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/7.jpg)
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
![Page 8: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/8.jpg)
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
![Page 9: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/9.jpg)
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
![Page 10: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/10.jpg)
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
![Page 11: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/11.jpg)
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]
![Page 12: Memory-mapped I/O. Mapping Loose definition: to transform something into a well-understood form Examples: a road map musical notation data mapping](https://reader035.vdocuments.us/reader035/viewer/2022072014/56649e7b5503460f94b7bb60/html5/thumbnails/12.jpg)
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