Task

Write a    for    loop which writes a countdown from   10   to   0.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


       .model small ;.exe file, max 128 KB
       .stack 1024  ;reserve 1 KB for the stack pointer.
 
       .data
 
       ;no data needed
 
       .code
start:
 
	mov ax,0100h	;UNPACKED BCD "10"
	mov cx,0Bh	;loop counter
 
repeat_countdown:
	call PrintBCD_IgnoreLeadingZeroes
	sub ax,1
	aas			
	;ascii adjust for subtraction, normally 0100h - 1 = 0FFh but this corrects it to 0009h
	push ax
		mov dl,13
		mov ah,02h
		int 21h
 
		mov dl,10
		mov ah,02h
		int 21h
		;these 6 lines of code are the "new line" function
	pop ax
	loop repeat_countdown ;decrement CX and jump back to the label "repeat_countdown" if CX != 0
 
 
 
	mov ax,4C00h
	int 21h			;return to DOS
 
PrintBCD_IgnoreLeadingZeroes:
	push ax
		cmp ah,0
		jz skipLeadingZero
			or ah,30h         ;convert a binary-coded decimal quantity to an ASCII numeral
			push dx
			push ax
				mov al,ah
				mov ah,0Eh
				int 10h	   ;prints AL to screen
			pop ax
			pop dx
skipLeadingZero:
		or al,30h
		push dx
		push ax
			mov ah,0Eh
			int 10h		   
		pop ax
		pop dx
	pop ax
	ret
 
        end start ;EOF