I have been dealing with Nasm and GNU C inline asm on a Linux environment for some time and this function worked great... but now I am switching to a windows environment and I want to use Masm (with VS2008) I cant seem to get this to work...
void outportb (unsigned short _port, unsigned short _data)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
When I write something like this...
void outportb (unsigned short _port, unsigned short _data)
{
asm volatile ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
asm is no more recognised and volatile throws an error saying "string", I also tried writing _asm volatile but I get an error saying "inline assembler syntax error in 'opcode'; found 'data type'"
Assuming you're talking about x86 command set, here are few things to remember:
Here is the code (assuming you're writing into 16-bit port):
void outportw(unsigned short port, unsigned short data)
{
__asm mov ax, data;
__asm mov dx, port;
__asm out dx, ax;
}
in case you're writing into 8-bit port, the code should look like that:
void outportb(unsigned short port, unsigned char data)
{
__asm mov al, data;
__asm mov dx, port;
__asm out dx, al;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With