汇编中如果汇编和调用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
@@:
  
   invoke MessageBoxA,NULL,CTEXT("13"),CTEXT("13"),MB_OK
  
 loop @B
 
 invoke ExitProcess,0
 
end START

 

 

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

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

 

 

在调用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

上一篇:引用 运行asp.net程序时候,编译器错误消息: CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Fra


下一篇:CorelDraw(CDR)教程:制作漂亮条纹的方法步骤