注册 登录
编程论坛 汇编论坛

关于把数字存入数组的问题(就要考试啦啦啦啦。。。)

eternuii 发布于 2014-10-25 21:54, 3967 次点击
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    char message1[] = "Enter the input: ";
    char format[]= "%d"; // format string for the scanf function

    int input;
    int myarray[5];
    _asm{  
        mov ebx, 0;
        lea ebx, myarray;
 label1:lea eax, message1;
        push eax; //print message1
        call printf;
        add esp, 4;
         
        lea eax, input;
        push eax;
        lea eax, format; //read the input
        push eax;
        call scanf;
        add esp, 8

        mov eax, input;
        add myarray[ebx], eax;
        add ebx, 4;
        jmp label1;

    }



    return 0;
}
为什么运行的时候会一直存下去。。。还有为什么会出现Stack around the variable 'format' was corrupt?小女跪求大神帮忙T。T  木有多少分了。。。就这么多了。。。T_T
1 回复
#2
wp2319572014-10-27 08:43
没太弄明白你想干嘛   不过估计你的代码跑不起来

这个是我在vs 能通过测试的一段代码

程序代码:

#include <stdio.h>

int main(void)
{
    char message1[] = "Enter the input: ";
    char message2[] = "您所输入的数字是%d . \n";
    char format[]= "%d";
    int input;
    _asm
    {  
          lea eax, dword ptr message1;
        push eax;
        call dword ptr printf;
        add esp, 4;
        lea eax, dword ptr input;
        push eax;
        lea edx, dword ptr format;
        push edx;
        call dword ptr scanf;
        add esp, 8;
        mov eax, input;
        push eax;
        lea eax, dword ptr message2;
        push eax;
        call dword ptr printf;
        add esp,8;
     }
    return 0;
}
1