首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么会有无限的循环?

为什么会有无限的循环?
EN

Stack Overflow用户
提问于 2014-01-07 12:41:16
回答 1查看 321关注 0票数 0

我只是想打印数组的元素。从输出中,我可以看到循环超出了数组的分配内存。

代码语言:javascript
复制
.386 ; 386 Processor Instruction Set

.model flat,stdcall 

option casemap:none 
include \masm32\include\masm32rt.inc
include \masm32\include\windows.inc 
include \masm32\include\kernel32.inc 
includelib \masm32\lib\kernel32.lib  

.data

array DWORD 72,50,22,0
asd DWORD ?

start:

mov ecx, 4
mov edi, 0
//-- loop start--//
loop_start:

mov eax, [array + edi * 4] 

push offset asd
push eax
call dwtoa


Invoke StdOut, addr asd

inc edi  //incrementing edi
dec ecx  // decrementing ecx
cmp ecx,0 // comparing ecx against 0


jne loop_start // if not equal loop again
//--loop end--//


invoke ExitProcess, 0
end start 

这是输出

编辑:试图在末尾添加

代码语言:javascript
复制
cmp ecx,0
je loop_end


loop_end:
Invoke ExitProcess,0

这些都不管用。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-07 16:03:15

这两个指令似乎改变了ecx寄存器:

代码语言:javascript
复制
call dwtoa
Invoke StdOut, addr asd

我猜dwtoa可能会返回在ecx寄存器中返回的asci数组的长度。

试试这个:

代码语言:javascript
复制
loop_start:

mov eax, [array + edi * 4] 

push ecx // saving ecx before call

push offset asd
push eax
call dwtoa


Invoke StdOut, addr asd

pop ecx // restore the ecx from before the calls.

inc edi  //incrementing edi
dec ecx  // decrementing ecx
cmp ecx,0 // comparing ecx against 0


jne loop_start // if not equal loop again
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20971909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档