【发布时间】:2015-11-11 02:42:24
【问题描述】:
我无法弄清楚如何在我的循环中进行索引。我知道esi 用于索引,所以我正在尝试使用它...
scores DWORD MAXIMUMSCORES DUP(0)
optionPromptMsg byte "Type 1 to continue or -1 to exit: ", 0
scorePromptMsg byte "Enter your numeric score (0-100): ", 0
scoreErrorMsg byte "Score out of range (0-100)!", 0
optionErrorMsg byte "Only 0 or 1 allowed in option specification!", 0
resultMsg byte " scores have been entered.", 0
.code
main proc
mov esi, 0
L1:
mov edx, offset optionPromptMsg
call WriteString
call ReadInt
mov ebx, 1
cmp eax, ebx
je L2
mov ebx, -1 //99% sure my main is okay
cmp eax, ebx
je L3
mov ebx, -2
mov ecx, 2
cmp ebx, eax
ja L4
cmp eax, ecx
ja L4
L2: call NextScore
jmp L5
L4: mov edx, offset optionErrorMsg
call WriteString
call Crlf
jmp L5
L5:
loop L1
L3 : call WriteScore
exit
main ENDP
WriteScore PROC USES esi //Thought was somehow make esi global?
mov eax, lengthof scores //total number of items added to array
call writeInt
mov edx, offset resultMsg
call WriteString
mov esi,0
L1:
mov eax, scores[esi *4]
call writeInt //writes the numbers in the array
inc esi
loop L1
mov eax, 5000
call Delay
ret
WriteScore ENDP
NextScore PROC USES esi
mov edx, offset scorePromptMsg
call WriteString
call ReadInt
mov ebx, 0
mov ecx, 100
cmp ebx, eax
ja L1
cmp eax,ecx
ja L1
jmp L2
L1:
mov edx, offset scoreErrorMsg
call WriteString
call Crlf
L2:
mov scores[esi*4], eax //gets the next number and puts it in the array
inc esi
ret
NextScore ENDP
当我运行它并向数组中添加 3 个项目时,无论出于何种原因,它都说 scores 的长度为 20,然后当它打印出数组时,数字甚至不接近我的数字期待,通常是数百万或只是0。
非常感谢任何建议!
【问题讨论】:
-
添加源的剩余部分。 最低限度,代码需要包含您的
ReadInt和WriteString函数。此外,您应该在调试器中运行它 - 如果这是基于 dos 的,请使用 Turbo Debugger 如果您调试代码,您将很快看到您的错误。 ;) -
@enhnzflep 我正在使用 Visual Studio 编写它,并且它的调试器很好.. 在我看来狗 sh*t。你说的这个涡轮调试器是什么?添加源代码的其余部分是什么意思?
-
@enhzflep :他正在使用 Irvine32 库。一些有用的信息是here
-
运气减半!有趣的是,我安装 VS 的唯一原因是它的调试器。Turbo Debugger 不会帮助你,因为它适用于在 dos(或 DosBox)下运行的 16 位程序。 @MichaelPetch - 哦,我明白了。 :嗅探:
-
他的代码是 32 位的,所以如果他设置了库,他应该能够轻松地在 VS 中使用调试器。
标签: arrays assembly indexing x86 masm