简体   繁体   中英

If I print newline then My loop doesn't stop

I wand to print star as many as user's input value but when I print a newline then my loop doesn't work otherwise without printing newline my code works fine. Why it's happening i don't understand.

.model small
.stack 100h
.data
   msg1 db "How many star do you want to print: $"
   newline db 10,13,"$"
.code
    main proc

    mov ax,@data
    mov ds,ax 

    mov ah,9
    lea dx,msg1
    int 21h

    mov ah,1   ;taking input number
    int 21h

    mov bl,al
    sub al,48

    ;if i add newline code here then my loop doesn't stop 

    ;   mov ah,9
    ;   mov ah,newline
    ;   int 21h

    loop:
    mov cx,0
    mov cl,al
    mov ah,2
    mov dl,'*'

    Top:
    int 21h
    loop Top


    Exit:   
    endp
    end main

The instruction loop uses register cx to count and repeat the process, so you can move the number of asterisk from al into cl :

mov ah,1   ;taking input number
int 21h

xor cx,cx     ;◄■■ CLEAR CX.
mov cl,al     ;◄■■ CX NOW HOLDS THE NUMBER OF ASTERISKS.
sub cl,48

;if i add newline code here then my loop doesn't stop 
   mov ah,9
   lea dx,newline     ;◄■■ UNCOMMENT LINE BREAK.
   int 21h

loop:
;mov cx,0      ;◄■■ HERE WE CANNOT CHANGE CX BECAUSE
;mov cl,al     ;◄■■ IT IS THE COUNTER FOR THE LOOP.
mov ah,2
mov dl,'*'

Top:
int 21h
loop Top     ;◄■■ CX--. IF CX>0 JUMP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM