所以我正在上汇编语言课程,我们正在尝试从输入创建和排序数组。我可以很好地掌握排序逻辑,但是我在尝试遍历数组时遇到了很大的困难。
为了进一步说明以下代码的作用,我们应该从命令行中读取整数。数字0表示用户输入的结束,然后调用排序方法。
这个方面还算顺利,但是数组迭代却不起作用。
下面是我所做的示例。
为了进一步说明以下代码的作用,我们应该从命令行中读取整数。数字0表示用户输入的结束,然后调用排序方法。
这个方面还算顺利,但是数组迭代却不起作用。
下面是我所做的示例。
main:
mov ebx, array ;move the variable array to ebx
mov ecx, 0 ;set ecx to zero
jmp input ;jump to input
input:
mov edx, 0 ;move 0 to edx
call ReadInt ; read in an integer from input to eax
cmp eax, edx ; compare the integer to 0
je sort ;jump if it equals zero to the sort method
mov [ebx+ecx], eax ;moves eax to the ecxth element of the array stored in ebx
add ecx, 1 ;increment ecx by 1
jmp input ; jump back to input
当我在后面的函数中打印数组时,无论我选择哪个元素,它总是一些疯狂的大数字。
我的逻辑在上面的代码片段中是错误的吗?你有什么改进建议吗?
mov edx, 0
,而是直接使用cmp eax, 0
。 - owacoder