为什么我的程序有无限循环?

Why my program have a infinite loop?

我使用汇编语言编写了一个简单的程序,为了实现我在这里使用 MS-DOS (DOSBox) 代码 :

.model small
.code
org 100h

mulai:

mov ah, 02h
mov dl, 'Z'
mov cx, 10h

lagi:

int 21h
inc dl
inc cx

loop lagi
int 20h

end mulai

我尝试了 loop 实现,但获得了 infinite loop,那么我的代码有什么问题吗?

loop 递减 cx,如果 cx 不为 0,则跳转到给定的地址。

由于您在每次循环迭代中递增 cx,因此 cx 永远不会变为 0,并且您有一个无限循环。