please can anyone help me with this homework i do not know what to do. thank you
1.
Write a program that will count from any user-inputted number to 0. For example, if the user inputs 5, the program should output: 5, 4, 3, 2, 1, 0.

Recommended Answers

All 6 Replies

Do you actually need the comma character also?
If not, check this out:
It is fixed to take only a single digit number.

; CntDown
	mov SI, 005Dh	; location of command-line parameter
	mov cx, [SI]	; put value in CX
	cmp cl, 20h	; Is the value empty?
	je quit		; if so, quit
print_it:		;
	mov ch, 24h	; Put a dollar-sign (terminator) (reversed)
	mov [si], cx	; Move that value and dollar sign to command-line
	mov ah, 09h	; Prepare to print
	mov dx, 005dh	; ...from command-line memory
	int 21h		; Print it.
	dec cl		; decrement value
	cmp cl, 2Fh	; Is it still above zero (hex 30)?
	jne print_it	; if not, print it.
quit:
	int 20h		; drop to DOS (the easy way)

I couldn't find my book, so I did this from memory.

To take a multi-digit number, you have to write your own string input routine, it does not take a great deal of time.

To create a 'buffer' to store each character

STORAGE times 50 db 0

Allows for up to 50 inputted characters.
To access each position in the buffer, you'd do something similar to
mov [STORAGE + 0],al
Position 0 = Position 1 on the buffer

What I normally do, it use a counter to auto-position each character as they are typed.

mov byte [bx],0
START:
cmp bx,51     ;Check if buffer is full..
je FULLBUFFER  ;If it is, flag an error
mov ah,0
int 16h
mov [STORAGE + bx],al
inc bx
jmp START

FULLBUFFER:
put error codes here..

I will not write the entire thing for you, the only real hard part is writing your own backspace routines.

You could turn the multi-digit value into unpacked BCDS...

jmp start
buf times 2 db 0
start:
mov dx, buf
mov cx, 2
mov bx, 0
mov ah, 3fh ; Read Dev/File Handle
int 21h
sub byte [buf], 0x30
sub byte [buf+1], 0x30

'21'=3231-3030=0201

def main():
x = input("number: ")
while ( x >= 0 ):
print x
x = x - 1
main()

You could, there are a few ways that you can do it. The way I showed is just the way I use and prefer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.