带汇编程序的无限循环

时间:2011-08-07 04:58:27

标签: windows loops x86 dos assembly

好的,我是PC Assembler的新手。我正在尝试编写一个程序,但它不会停止循环。我猜测ECX寄存器正在被修改?我该如何修复它?谢谢。

DATA SECTION
;
KEEP DD 0                   ;temporary place to keep things
;
CODE SECTION
;
START:
MOV ECX,12
TOPOFLOOP:
PUSH -11                        ;STD_OUTPUT_HANDLE
CALL GetStdHandle           ;get, in eax, handle to active screen buffer
PUSH 0,ADDR KEEP            ;KEEP receives output from API
PUSH 5,'bruce'                  ;5=length of string
PUSH EAX                    ;handle to active screen buffer
CALL WriteFile
XOR EAX,EAX                 ;return eax=0 as preferred by Windows
LOOP TOPOFLOOP
ENDLABEL:
RET

1 个答案:

答案 0 :(得分:2)

在大多数x86调用约定中,包括Windows API函数使用的stdcall约定,ECX是一个调用者保存寄存器 - 不需要调用函数来确保寄存器的值是相同的它会在调用时返回。您必须将它保存在您自己的代码中的安全位置。

相关问题