Answer to Question #350292 in Assembler for mariaaaaaa

Question #350292

Basic Looping Task:

Display sets of "*" based on the user's integer input (0-9).


Example:

Enter a number: 6

******


1
Expert's answer
2022-06-13T08:26:18-0400
; DosBox
DATA SEGMENT
msgEnterN    db "Enter a number (0-9): $"
invalid        DB 10,13,"Invalid input.",0ah,0dh,'$'
NewLine        db     10,13,'$'
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
    MOV AX,DATA
    MOV DS,AX

    mov dx, offset msgEnterN
    mov ah, 9
    int 21h    
    
; wait for any key press:
    mov ah, 0
    int 16h    
    mov ah, 0eh
    int 10h  
    
; Check input
   cmp al,'0'
   jl _error        ; char < '0'
   cmp al,'9'        ; char > '9'
   jg _error

; AL = ASCII code of key pressed
    SUB al, 30H        ; AL NUMBER
    xor cx,cx
    mov cl,al        ; CL NUMBER
    
    cmp cl,0
    jz _final
    
     mov dx, offset NewLine
    mov ah, 9
    int 21h
    
 _loop:
    mov ah, 0eh
    mov al,'*'
    int 10h
  loop _loop
 
    mov dx, offset NewLine
    mov ah, 9
    int 21h   
   jmp _final
   
_error:
   mov dx, OFFSET invalid
       mov ah, 9
    int 21h      
 
_final:    
    mov ah, 4Ch
    int 21h
CODE ENDS
END START

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS