Conversion Problem: __asm__ __volatile

For some time I was doing Nasm in the linux environment and this function worked fine ... but now I am going to the Windows environment and I want to use Masm (with VS2008). I can't 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 longer recognized, and volatile gives the error message "string", I also tried to write _asm volatile, but I get the error message "syntax error of the assembler in" opcode "; found" data type "

+5
source share
1 answer

, x86, :

  • "outb" , "char" "unsigned char" C/++. 16- ( "unsigned short" ), "outw"
  • , Intel ( VS) "" "out", . , "out dx, ax" "outw", "out dx, al" "outb"
  • x86 "out" , (e) dx {eax/ax/al} . Nasm ( , ), VS , .
  • "volatile" __asm. , VS ( volatile)

(, 16- ):

void outportw(unsigned short port, unsigned short data)
{
    __asm  mov ax, data; 
    __asm  mov dx, port; 
    __asm  out dx, ax;
}

8- , :

void outportb(unsigned short port, unsigned char data)
{
    __asm  mov al, data; 
    __asm  mov dx, port; 
    __asm  out dx, al;
}
+8

All Articles