Mustafa Irer
Mustafa Irer

Reputation: 45

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
    }
}

Upvotes: 1

Views: 1217

Answers (3)

Seva Alekseyev
Seva Alekseyev

Reputation: 61378

Assembly is not a high level language, where you can plug an arbitrary expression anywhere. The out command can only take an Ax register for a second operand, where Ax means AL, AX, or EAX. So reformulate like this:

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

The out command is privileged; it only works in kernel level drivers on Windows, trying to do it in a regular program will get you an "Invalid operation" error.

Upvotes: 1

user555045
user555045

Reputation: 64913

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).

Upvotes: 5

ymgve
ymgve

Reputation: 328

What target platform are you using for your C++ dll? You need to compile to x86 code, not CLR.

Upvotes: 0

Related Questions