简体   繁体   English

内联汇编,输出指令

[英]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. 我试图导出.dll文件,并试图在我的C#应用​​程序中使用它来将数据写入端口。 In my .cpp file (to create a .dll) if I use "out" command it gives "error C2415: improper operand type" error message. 在我的.cpp文件中(用于创建.dll),如果我使用“ out”命令,则会显示“错误C2415:操作数类型不正确”错误消息。 Do you have any idea why i cannot use this "out" command? 您是否知道为什么我不能使用此“输出”命令? ("mov" command is working well btw) (顺便说一句,“ mov”命令运行良好)

See my code below: 请参阅下面的代码:

#include <stdio.h>

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

out has six forms: out有六种形式:

  • 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. 我对x86上的IO端口没有太多经验,但是从我发现的情况来看,66和62对我来说似乎有点可疑。 Shouldn't they be 66h and 62h? 他们不是66h和62h吗? 41h (could be two flags set, or ASCII 'A') also makes a little more sense to me than 41 (a rather arbitrary number). 41h(可以设置两个标志,或ASCII'A')对我来说比41(一个相当随意的数字)更有意义。

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. out命令只能将Ax寄存器用于第二个操作数,其中Ax表示AL,AX或EAX。 So reformulate like this: 像这样重新编写:

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

The out command is privileged; out命令具有特权; it only works in kernel level drivers on Windows, trying to do it in a regular program will get you an "Invalid operation" error. 它仅在Windows的内核级驱动程序中有效,尝试在常规程序中执行此操作将使您收到“无效操作”错误。

What target platform are you using for your C++ dll? 您的C ++ dll使用什么目标平台? You need to compile to x86 code, not CLR. 您需要编译为x86代码,而不是CLR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM