简体   繁体   English

在Win 7 64位上在Visual Studio 2012中编写x86汇编代码时遇到的问题

[英]problems in writing x86 assembly code in visual studio 2012 on win 7 64 bit

I want to create an application that shows an array of character in console with x86 assembly language. 我想创建一个使用x86汇编语言在控制台中显示字符数组的应用程序。 i write it in Visual Studio 2012 Ultimate Version. 我在Visual Studio 2012 Ultimate Edition中编写它。 In addition my Windows is 7 64 bit. 另外我的Windows是7 64位。 When run it in compiler, I mean in visual studio, I've this error: 在编译器中运行它时,我的意思是在Visual Studio中出现此错误:

main.cpp(8):  error C2443: operand size conflict
main.cpp(11): error C2432: illegal reference to 16-bit data in 'second operand'

My code is: 我的代码是:

void main(){
    char nameAndId[] = "name:mohammad mahdi derakhshani .\n";
    int sc=-1;
    while(nameAndId[sc++]!=0){
        _asm{
            push si
line 8:     mov si,sc

            xor edx,edx
line 10:    mov dl,nameAndId[si]
            mov ah,2
            int 21h
            pop si
        }
    }
}

How can i fix this problem? 我该如何解决这个问题?

You are using 16-bit SI register instead of 32-bit one ESI . 您使用的是16-bit SI寄存器,而不是32位一个ESI

For the other side, I don't know if int 21 still works but I recommend to get a pointer to WriteConsoleA api using GetProcAddress and call the api instead of using the old dos functions. 另一方面,我不知道int 21仍然有效,但我建议使用GetProcAddress获取指向WriteConsoleA api的指针,然后调用该api,而不是使用旧的dos函数。

Third: When the loop begins, sc equal -1, so you reference nameAndId[-1] . 第三:循环开始时, sc等于-1,因此您引用nameAndId[-1] Change sc++ with ++sc . ++sc更改sc++

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

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