首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 汇编语言 >

读老罗WIN32有关问题

2012-03-19 
读老罗WIN32问题我想要建一个窗口,然后按下BUTTON弹出一个消息窗口,显示movebp,1,lea,eax, [ebp + 1234567

读老罗WIN32问题
我想要建一个窗口,然后按下BUTTON弹出一个消息窗口,显示movebp,1,lea,eax, [ebp + 12345678h] EAX的值
但按下BUTTON总是显示应用程序停止工作,环境是WIN7.
还有我看到一个大牛写的一个帖子里面,说这里说eax等于123456789h,我想不是等于12345679h吗?
下面是代码

Assembly code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;数据段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        .data?hInstance    dd    ?hWinMain    dd    ?        .constszMessage    db    'EAX= %x',0szClassName    db    'WinTest',0szCaption    db    'WinTest',0szButton    db    'Button',0;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;代码段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        .code;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_ProcWinMain    proc    hWnd,uMsg,wParam,lParam        LOCAL    @szBuffer[256]:byte                pushad        mov    eax,uMsg        .if    eax ==    WM_CREATE            invoke    CreateWindowEx,NULL,\                offset szButton,offset szCaption,\                WS_CHILD or WS_VISIBLE,\                10,10,65,22,\                hWnd,1,hInstance,NULL;******************************************************************        .elseif    eax ==     WM_COMMAND            mov    ebp,1            lea    eax, [ebp + 12345678h]            invoke    wsprintf,addr @szBuffer,offset szMessage,eax            invoke    MessageBox,hWnd,addr @szBuffer,offset szCaption,MB_OK                        ;[color=#FF0000]就是在这里弹出消息啊。但总是显示程序已停止工作[/color]。;******************************************************************        .elseif    eax == WM_CLOSE                        invoke    DestroyWindow,hWinMain            invoke    PostQuitMessage,NULL;******************************************************************        .else            invoke    DefWindowProc,hWnd,uMsg,wParam,lParam            ret        .endif        ;xor    eax,eax        popad        ret_ProcWinMain endp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_WinMain    proc            LOCAL    @stWndClass:WNDCLASSEX        LOCAL    @stMsg:MSG                invoke    GetModuleHandle,NULL        mov    hInstance,eax        invoke    RtlZeroMemory,addr @stWndClass,sizeof @stWndClass;*******************************************************************;注册窗口类;*******************************************************************        invoke    LoadCursor,0,IDC_ARROW        mov    @stWndClass.hCursor,eax        push    hInstance        pop    @stWndClass.hInstance        mov    @stWndClass.cbSize,sizeof WNDCLASSEX        mov    @stWndClass.style,CS_HREDRAW or CS_VREDRAW        mov    @stWndClass.lpfnWndProc,offset _ProcWinMain        mov    @stWndClass.hbrBackground,COLOR_WINDOW +1        mov    @stWndClass.lpszClassName,offset szClassName        invoke    RegisterClassEx,addr @stWndClass;*******************************************************************;建立并显示窗口;*******************************************************************        invoke    CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaption,WS_OVERLAPPEDWINDOW,\            100,100,600,400,\            NULL,NULL,hInstance,NULL        mov    hWinMain,eax        invoke    ShowWindow,hWinMain,SW_SHOWNORMAL        invoke    UpdateWindow,hWinMain;*******************************************************************;消息循环;*******************************************************************        .while    TRUE            invoke    GetMessage,addr @stMsg,NULL,0,0            .break    .if eax == 0            invoke    TranslateMessage,addr @stMsg            invoke    DispatchMessage,addr @stMsg                    .endw    ret_WinMain endp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start:        call    _WinMain        invoke    ExitProcess,NULL;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        end    start 



[解决办法]
怎么能在子程里乱改 ebp 呢?ebp 是被用作访问局部变量和参数的。非得用它,也只能是在不涉及对局部变量和参数的访问时,而且还应该进行保存后恢复的操作:
Assembly code
    push    ebp    ; *** 必须先行保存            mov    ebp,1            lea    eax, [ebp + 12345678h]    pop    ebp    ; *** 还应进行恢复!这中间还不能有对局部变量或参数的访问! 

热点排行