• Basic Looping Task:
Based on the user's integer input (0-9).
Display sets of "*"
Example:
Enter a number: 6
******
; DosBox
DATA SEGMENT
msgEnter db "Enter a number (0-9): $"
invalid DB 10,13,"Invalid input.",0ah,0dh,'$'
NL db 10,13,'$'
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
mov dx, offset msgEnter
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 _wrong ; char < '0'
cmp al,'9' ; char > '9'
jg _wrong
; 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 NL
mov ah, 9
int 21h
L1:
mov ah, 0eh
mov al,'*'
int 10h
loop L1
mov dx, offset NL
mov ah, 9
int 21h
jmp final
_wrong:
mov dx, OFFSET invalid
mov ah, 9
int 21h
final:
mov ah, 4ch
int 21h
CODE ENDS
END START
Comments
Leave a comment