Search code examples
c++assemblyiox86

Inline assembly, out instruction


I am trying to export a .dll file and trying to use it in my c# application to write a data to a port. In my .cpp file (to create a .dll) if I use "out" command it gives "error C2415: improper operand type" error message. Do you have any idea why i cannot use this "out" command? ("mov" command is working well btw)

See my code below:

#include <stdio.h>

extern "C" __declspec(dllexport) void enableWatchDog()
    _asm {
          out 66,41
          out 62,4
    }
}

Solution

  • out has six forms:

    • out imm8, AL
    • out imm8, AX
    • out imm8, EAX
    • out DX, AL
    • out DX, AX
    • out DX, EAX

    Your usages match none of them. Perhaps this would work (not tested):

    mov al, 41
    out 66, al
    mov al, 4
    out 62, al
    

    I don't have too much experience with IO ports on x86, but from what I've been able to find, 66 and 62 seem a little suspicious to me. Shouldn't they be 66h and 62h? 41h (could be two flags set, or ASCII 'A') also makes a little more sense to me than 41 (a rather arbitrary number).