1

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
    }
}
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Mustafa Irer
  • 45
  • 1
  • 5
  • 3
    What's the platform? Windows? If so, are you writing a driver? If not, `out` won't ever work, your program will just force-close. – Seva Alekseyev Aug 06 '12 at 15:31
  • If you try to create a timer under Windows, please look at [How to create timer in WinApi](http://stackoverflow.com/questions/2128620/how-to-create-timer-in-winapi-c) – Bo Persson Aug 06 '12 at 15:48

3 Answers3

5

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

harold
  • 61,398
  • 6
  • 86
  • 164
1

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.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
0

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

ymgve
  • 318
  • 2
  • 7