CS251-101-T5s

advertisement
CS-251
Tutorial 5
Exercise 1
Write a program which takes a number as an input ( from 1 to 9) and display your
name that much amount of times on next line. (Use While loop)
Note: Always write comments with your assembly code.
Output of Program:
Enter the number: 2
My name is Salma Idris
My name is Salma Idris
SOLUTION
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter a number: $'
PROMPT_2 DB 0DH,0AH,'MY NAME IS SALMA IDRIS $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, PROMPT_1
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
XOR CL,CL
MOV CL, AL
SUB CL, 30H
MYLOOP:
; initialize DS
; load and display the string PROMPT_1
; set input function
; read a character
; Clear CL used as counter
; set CL=AL
; converting the input number to decimal form
CMP CL, 0
JE EXIT
; compare CL with 0
; jump to label EXIT IF TRUE
DEC CL
; Decrement the counter
MOV AH,9
LEA DX, PROMPT_2
INT 21H
JMP MYLOOP
; DISPLAY YOUR NAME
EXIT:
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; jump to MYLOOP AGAIN
; return control to DOS
Download