码迷,mamicode.com
首页 > Windows程序 > 详细

汇编中如果汇编和调用API混合用的话要注意Pushad popad

时间:2014-09-28 03:01:10      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   sp   div   2014   

某群有个人提出一个奇怪的问题,这段代码的循环不正常

;MASMPlus 代码模板 - 控制台程序

.386
.model flat, stdcall
option casemap :none

include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
include gdi32.inc

includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm
.data
 lpMsg  db "Hello World!",0
 
.data?
 buffer db MAX_PATH dup(?)
 
.CODE
START:
  
 mov ecx,5
@@:
  
   invoke MessageBoxA,NULL,CTEXT("13"),CTEXT("13"),MB_OK
  
 loop @B
 
 invoke ExitProcess,0
 
end START

 

 

按道理Loop等于ECX-1,然后查看ECX==0,如果相当则不循环,如果不等于则进行循环,但是这个ECX却不是5

bubuko.com,布布扣

 

 

在调用Api前后加入pushad popad则正常了

;MASMPlus 代码模板 - 控制台程序

.386
.model flat, stdcall
option casemap :none

include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
include gdi32.inc

includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm
.data
    lpMsg        db "Hello World!",0
    
.data?
    buffer    db MAX_PATH dup(?)
    
.CODE
START:
   
    mov ecx,5
@@:
   pushad
   invoke MessageBoxA,NULL,CTEXT("13"),CTEXT("13"),MB_OK
   popad
    loop @B
    
    invoke ExitProcess,0
    
end START

 

汇编中如果汇编和调用API混合用的话要注意Pushad popad

标签:style   blog   http   color   io   ar   sp   div   2014   

原文地址:http://www.cnblogs.com/qq32175822/p/3997517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!