;---------------------------------------------------------------------------      
; Convert number to a string of digits for print. Requires in DATASEG:
; numstr db '$$$$$'. Proc dollars fills numstr with $ signs and proc
; number2str receive a number in ax and create the string in numstr.

proc          dollars        ;No parms. Fills area in memory with "$" 
              push cx  
              push di              
              mov  cx, 5
              mov  di, offset numstr
dollars_loop: mov  bl, '$'      
              mov  [ di ], bl
              inc  di
              loop dollars_loop
              pop  di
              pop  cx	
              ret
endp          dollars
;---------------------------------------------------------------------------
proc          number2string  
              push cx
              push ax
              push dx
              push bx
              
              call dollars  ;FILL STRING WITH $.
              mov  bx, 10   ;DIGITS ARE EXTRACTED DIVIDING BY 10.
              mov  cx, 0    ;COUNTER FOR EXTRACTED DIGITS.
;EXTRACT DIGITS               
cycle1:       mov  dx, 0    ;NECESSARY TO DIVIDE BY BX.       
              div  bx       ;DX:AX / 10 = AX:QUOTIENT DX:REMAINDER.
              push dx       ;PRESERVE DIGIT EXTRACTED FOR LATER.
              inc  cx       ;INCREASE COUNTER FOR EVERY DIGIT EXTRACTED.
              cmp  ax, 0    ;IF NUMBER IS NOT YET ZERO, LOOP.
              jne  cycle1   ; 
;NOW RETRIEVE PUSHED DIGITS.
              mov si, offset numstr
cycle2:       pop  dx           
              add  dl, 48   ;CONVERT DIGIT TO CHARACTER. 48 is '0' in ASCII 
              mov  [ si ], dl
              inc  si
              loop cycle2  
              pop bx
              pop dx
              pop ax
              pop cx
              ret
endp          number2string