Memory mapped I/O and inline assembly
Posted: Sun Aug 28, 2011 2:53 am
My question is about using inline assembly to create a function that replaced the IN and OUT instructions.
I'm working with C in Visual Studio 2010, and I can get things working if I use a separate NASM file. Eg, to setup the PIC, I use this:
...which works just fine. However I'm trying to create an outb function. I modified this one from the web:
I try to configure the PIC using this code, but it does not work:
I can't see where I'm going wrong. Can anyone help me?
I'm working with C in Visual Studio 2010, and I can get things working if I use a separate NASM file. Eg, to setup the PIC, I use this:
Code: Select all
MOV AL, 0x11
OUT 0x20, AL
OUT 0xA0, AL
MOV AL, 0x20
OUT 0x21, AL
MOV AL, 0x28
OUT 0xA1, AL
MOV AL, 0x4
OUT 0x21, AL
MOV AL, 0x2
OUT 0xA1, AL
MOV AL, 0x1
OUT 0x21, AL
OUT 0xA1, AL
Code: Select all
void outb (unsigned short portid, unsigned char value) {
__asm {
mov al, byte ptr [value]
mov dx, word ptr [portid]
out dx, al
}
}
Code: Select all
outb(0x20, 0x11);
outb(0xa0, 0x11);
outb(0x21, 0x20);
outb(0xa1, 0x28);
outb(0x21, 0x4);
outb(0xa1, 0x2);
outb(0x21, 0x1);
outb(0xa1, 0x1);