Search code examples
assemblydosdosbox

Why my program have a infinite loop?


I made a simple program using assembly language, for implementation I'm using MS-DOS (DOSBox) here the code :

.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

I tried loop implementation but gain infinite loop, so what wrong with my code ?


Solution

  • loop decrements cx, and jumps to the address given if cx is not 0.

    Since you increment cx on each loop iteration, cx will never become 0 and you have an infinite loop.