Click to See Complete Forum and Search --> : isolated I/O vs memory mapped I/O


brad sue
April 8th, 2009, 02:11 AM
Hi,
I am a bit confused about the style of programming for the isolated and memory mapped I/O (assembly for 8086).

For the mapped IO, I read we dont use the "IN" and "OUT" special instructions to respectively read and write to the ports.

My question is how can I translate input and output instructions when I deal with a memory mapped configuration?
Can I have an example please?
Thank you

Codeplug
April 8th, 2009, 09:12 AM
Here's some info on the subject: http://www.wd-3.com/archive/PioAccess.htm

gg

rxbagain
April 8th, 2009, 01:40 PM
When you deal with memory mapped I/O, all you need is to know what memory address the device is mapped to. When you get/know the address, simply exchange data between your app and that memory address range.

An example is controlling the video output in DOS. If you know where the video buffer is mapped, you can directly write into that memory range and it will show up on the screen. You can also read from it, giving you the content of the screen. Here's my sample code that uses the video mapped address 0xB800 to output a string. The memory contains 2 bytes for each character, one for the actual character and the other one for the attributes (e.g. color, blink, etc).

.8086
.model small
.stack 100h
.data
sztext db "Rex Bagain", 0
.code
.startup

mov ax, 0003h ; set video mode 3 (80x25)
int 10h

mov ax, 0b800h ; set ES the segment address of video mapped address
mov es, ax
mov di, 80 * 5 * 2 ; start printing from line 5

mov si, offset sztext
xor ax, ax ; AL will hold the character, AH will hold the attribute
cld
_print_it:
lodsb ; AL will hold the character to print
cmp al, 0 ; is it '\0' ?
jz _print_done ; if yes then stop printing
inc ah ; change the character attribute
stosw ; store character + attribute to the video memory ES:[DI]
jmp _print_it ; process the next character
_print_done:

.exit
end

Hope it will help you :)

brad sue
April 12th, 2009, 03:05 AM
Thank you rxbagain!