运行 如果最后一个数组值为负,则出现时间错误
Run time error if last array value is negative
我有这么一小段代码,它的目的是对负值求和并计算正值,向量在其他地方初始化
;sum all negative values and count positive values
;let eax hold sum and ebx hold number of positives
CALL crlf
mov ecx, VectorSize
mov eax, 0
mov ebx, 0
mov edx, 0
sumMe:
cmp Vector[edx * TYPE Vector], 0
jge pos
;neg
add eax, Vector[edx * TYPE Vector]
INC edx
loop sumMe
pos:
INC ebx
INC edx
loop sumMe
除非负值是数组中的最后一个值,否则这段代码可以正常工作,甚至像 -1 -1 -1 -1 5
这样的代码也可以。但是,如果我在最后一个位置有一个负值,程序就会崩溃。
任何帮助将不胜感激
假设最后有一个 ret
或其他东西:
当 ecx 达到零时 loop
做什么:执行失败。如果最后一个元素为负数,则使 ecx
为零的 loop
指令后跟 pos:
.
当 loop
以 ecx=0
开始运行时,ecx
换行到 0xFFFFFFFF
并进行跳转。 loop
就像 do{}while(--ecx);
的底部。
如果您使用调试器单步执行最后一次迭代,那么所有这些都会很明显,因为您已经知道问题出在数组末尾的负元素。
我有这么一小段代码,它的目的是对负值求和并计算正值,向量在其他地方初始化
;sum all negative values and count positive values
;let eax hold sum and ebx hold number of positives
CALL crlf
mov ecx, VectorSize
mov eax, 0
mov ebx, 0
mov edx, 0
sumMe:
cmp Vector[edx * TYPE Vector], 0
jge pos
;neg
add eax, Vector[edx * TYPE Vector]
INC edx
loop sumMe
pos:
INC ebx
INC edx
loop sumMe
除非负值是数组中的最后一个值,否则这段代码可以正常工作,甚至像 -1 -1 -1 -1 5
这样的代码也可以。但是,如果我在最后一个位置有一个负值,程序就会崩溃。
任何帮助将不胜感激
假设最后有一个 ret
或其他东西:
当 ecx 达到零时 loop
做什么:执行失败。如果最后一个元素为负数,则使 ecx
为零的 loop
指令后跟 pos:
.
当 loop
以 ecx=0
开始运行时,ecx
换行到 0xFFFFFFFF
并进行跳转。 loop
就像 do{}while(--ecx);
的底部。
如果您使用调试器单步执行最后一次迭代,那么所有这些都会很明显,因为您已经知道问题出在数组末尾的负元素。