user3110801
user3110801

Reputation: 1

loop within a loop in assembly

I just started programming in Assembly and I'm really confused about looping in Assembly.This is my code :

org 100h

Var db ?
Var2 db 65
Var3 db 0
mov ax,0
mov ah,01h
int 21h

mov Var,al

mov ah,02h
mov dl,10
int 21h

mov ah,02h
mov dl,13
int 21h

mov al,Var
sub al,64

mov cl,al

a:
    mov bl,cl
    mov ah,02h
    mov dh,Var2
    inc Var3
    mov cl,Var3
    inc Var2

b:                           
    mov ah,02h      
    mov dl,dh      
    int 21h      
    mov ah,02h      
    mov dl,0dh      
    int 21h          
    loop b     

    mov ah,02h
    mov dl,10
    int 21h

    mov ah,02h
    mov dl,13
    int 21h  

mov cl,bl
loop a

ret

It outputs something like this : (Input) F (Output) A B C D E F

or (Input) B (Output) A B

What I want to happen is this: (Input) F (Output) A BB CCC DDDD EEEEE FFFFFF

I really need help I spent hours racking my brain in this code. Please do so tell me what I did wrong or what I should do. Thanks

Upvotes: 0

Views: 310

Answers (1)

Devolus
Devolus

Reputation: 22074

When using a loop variable, the cx register is used as the counter. So here in the inner loop

    loop b     

You are using CX which becomes 0 in the process. Then your code continues with the outer loop

mov ah,02h
...
int 21h  

And again uses cx which is still 0 at the point.

mov cl,bl

So this outer loop

loop a

never loops.

Upvotes: 1

Related Questions