Assembly language: counter loop

Amina Nasrin

I have written an assembly code that includes:

    XOR BL,BL
    MOV CX,0 
TOP: 
    INC BL,1
    MOV AH,2 
    MOV DL, BL 
    INT 21H
    LOOP TOP

The loop is executed a really large number of times (more than 10,000 for sure). What could be the possible reason behind the loop execution of such a high time? I am very new in assembly language and found nothing efficient to my code related to CX=0. Thanks in Advance.

Jose Manuel Abarca Rodríguez

Your counter cx was not properly initialized. The instruction loop does two things:

dec cx            ;◄■■■ DECREASE THE COUNTER.
jnz label         ;◄■■■ IF COUNTER IS NOT ZERO, JUMP TO LABEL TO REPEAT.

In your code the counter cx was initialized as zero, so, when the loop instruction executes, it does cx - 1, which is 0 - 1, so cx becomes 0ffffh and your loop will repeat 0ffffh times.

Move another value to your counter cx, for example, mov cx, 10, so your loop will repeat 10 times.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related