Read a digit n and print the numbers from n down to 1, separated by single spaces.
Input
One digit n, 1 ≤ n ≤ 9.
Output
n, n − 1, ..., 1 on one line, with one space between numbers and none at the end.
Examples
Example 1 · Input
5
Expected output
5 4 3 2 1
Example 2 · Input
1
Expected output
1
Hints
Hint 1
Turn the digit into a number with SUB AL, '0' and put it in CX: LOOP will count with it.
Hint 2
Keep the digit to print in DL, starting at the character you read, and DEC DL each time round.
Hint 3
Print a space between the numbers, but not after the last one: print the space before every number except the first, or test CX.
Solution
Show one correct solution (try it yourself first)
; Count down
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV DL, AL ; the character to print first
SUB AL, '0'
MOV CL, AL
MOV CH, 0 ; CX = n
NEXT:
MOV AH, 2
INT 21H
DEC DL
CMP CX, 1
JE LAST ; no space after the last number
MOV BL, DL
MOV DL, ' '
INT 21H
MOV DL, BL
LAST:
LOOP NEXT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN