在我的顺序搜索程序中添加一些数组检查功能后出现一个奇怪的错误。经过一些阅读后,似乎这通常是因为堆栈损坏或数据不良而发生,但检查我的内存寄存器数据似乎不同意。有什么想法吗?
INCLUDE Irvine32.inc ; Irvine's assembly library
ExitProcess PROTO,dwExitCode:DWORD ; MS Windows ExitProcess function
.data
array1 DWORD 10,20,30,40,50,60,70,80,90,100 ;Test array, change as you see fit.
string BYTE "Choose Number, Press Enter When Ready: ", 0
.code
main PROC ; main procedure, entry point
mov ESI, OFFSET array1 ;move array to ESI for output
mov ECX, LENGTHOF array1 ;set up loop for outputting array
L1:
mov EAX, [ESI] ;move number from ESI to EAX
add ESI, 4 ;Have ESI point to next number
call WriteDec ;Output EAX
call Crlf
loop L1
call Crlf
mov EDX,OFFSET string
call WriteString ;outputs instruction string
call ReadInt ;recieves desired number from user, to EAX
call search ;call search procedure
call Crlf
call WaitMsg
INVOKE ExitProcess,0 ; end the program
main ENDP
search PROC
push ECX
push ESI
push EAX
push EDX
mov ESI, OFFSET array1 ;move array to ESI for output
mov ECX, LENGTHOF array1
L1:
cmp EAX, [ESI] ;compare user input to array index
JNE L2 ;if not equal, jump to L2 to INC ESI
mov EAX, LENGTHOF array1 ;for computing array position
sub EAX, ECX ;This will give current position
call WriteInt
call Crlf
L2:
cmp ECX, 0 ;determine if every element has been checked
JLE L3
add ESI,4 ;Make ESI point to next register
L3:
string1 BYTE "Integer not found" ;If ECX = 0, everything checked
mov EDX,OFFSET string1 ;means its not found, so output not found
call WriteString
call Crlf
loop L1
pop EDX
pop EAX
pop ESI
pop ECX
search ENDP
END
为了清楚一些事情,调用Crfl,WriteXXX,ReadInt和WaitMsg都来自我的教科书中的Irvine32库。他们移动光标,输出到控制台窗口,从窗口输入并分别声明系统暂停。 WriteDec需要EAX寄存器,WriteString需要EDX。 ReadInt将输入放入EAX。如果您想了解更多信息,请告诉我,我会告诉您完整的功能列表。
链接到项目,包括库:https://drive.google.com/open?id=18hwuVu8oJSyDZJtblwEZfjArChVbfhkL