J8II
05-14-08, 04:44 AM
Hi y'all. I tried so many times to get this right and I couldnt do it. Can someone please help me.
Here is what the program is supposed to do. If the character is a decimal digit n then output the digit n on the next line n+1 times, then move the cursor to a new line and repeat step 1. If the character is a <CR> then exit (You may assume that the inputs are either a digit or <CR>)
An example of a program run is:
C>PROG2
?1
11
?3
3333
?5
555555
?0
0
?
C>
I know Im supposed to convert the digit from ASCII to a number using SUB BL,30H (at least I think it should be BL). I couldnt figure out where to insert it to get the program to work correctly. Also the second thing I need help with which I really couldnt figure out at all is using the while loop to loop the whole program unless it's a <CR>.
Now here is what I have:
.MODEL SMALL
.386
.STACK
.CODE
MAIN PROC
;display prompt
MOV AH,2 ;display character function
MOV DL,'?' ;character is '?'
INT 21H ;display it
;input a character
MOV AH,1 ;read character function
INT 21H ;character in AL
MOV BL,AL ;save it in BL
;go to a new line
MOV AH,2 ;display character function
MOV DL,0DH ;carriage return
INT 21H ;execute carriage return
MOV DL,0AH ;line feed
INT 21H ;execute line feed
;for loop
MOV CL,BL ;number of times to display from input
MOV AH,2 ;display character function
MOV AL,CL
TOP:
INT 21h ;display the number
LOOP TOP
MOV AH,4CH ;DOS exit function
INT 21H ;exit to DOS
MAIN ENDP
END MAIN
Here is what the program is supposed to do. If the character is a decimal digit n then output the digit n on the next line n+1 times, then move the cursor to a new line and repeat step 1. If the character is a <CR> then exit (You may assume that the inputs are either a digit or <CR>)
An example of a program run is:
C>PROG2
?1
11
?3
3333
?5
555555
?0
0
?
C>
I know Im supposed to convert the digit from ASCII to a number using SUB BL,30H (at least I think it should be BL). I couldnt figure out where to insert it to get the program to work correctly. Also the second thing I need help with which I really couldnt figure out at all is using the while loop to loop the whole program unless it's a <CR>.
Now here is what I have:
.MODEL SMALL
.386
.STACK
.CODE
MAIN PROC
;display prompt
MOV AH,2 ;display character function
MOV DL,'?' ;character is '?'
INT 21H ;display it
;input a character
MOV AH,1 ;read character function
INT 21H ;character in AL
MOV BL,AL ;save it in BL
;go to a new line
MOV AH,2 ;display character function
MOV DL,0DH ;carriage return
INT 21H ;execute carriage return
MOV DL,0AH ;line feed
INT 21H ;execute line feed
;for loop
MOV CL,BL ;number of times to display from input
MOV AH,2 ;display character function
MOV AL,CL
TOP:
INT 21h ;display the number
LOOP TOP
MOV AH,4CH ;DOS exit function
INT 21H ;exit to DOS
MAIN ENDP
END MAIN