【发布时间】:2017-11-13 12:13:12
【问题描述】:
我编写了一个程序来从 15 个数字的数组中查找最大数字,但我的输出出错了。我已将结果存储在 AX 寄存器中。
这是我的代码。
[org 0x0100]
array_nums: dw 19, 50, 30, 24, 19, 2, 5, 6, 40, 8, 23, 16, 17, 28, 86
max: dw 0
mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize min to zero
mov ax, [array_nums+bx] ; max number to ax
mov cx, 15
maxvalue: cmp ax, [array_nums+bx] ; find the maximun number
jge maxloop ; if greater or equal number
mov ax, [array_nums+bx] ; ax contains the maximun number
maxloop:
add bx, 2 ; advance bx to next index
loop maxvalue
mov [max], ax ; write back maximun in memory
mov ax, 0x4c00 ; terminate program
int 0x21
【问题讨论】:
-
我没有看到你的程序产生任何输出。你得到什么输出?
-
在 AX 寄存器中我得到 49 值,在 BX 1E 中
-
不要把你的数据放在开头,否则会被当作代码执行。把它移到最后。另外,学习使用调试器。
-
@Jester 好的,感谢您提供此信息。
-
在“org 0x100”之后添加一个“jmp start”,在主程序的第一行之前添加一个“start:”标签,以设置入口点。此外,您可能想看看“lodsw”指令(faydoc.tripod.com/cpu/lodsw.htm)