; proc:  strnum  - get a string of digits and turn it into a number.
; '123' ->  123

; proc: numtoascii - get a number and turn it into a string of digits
; 123 -> '123$'

;  '1'   31h,   '0'  30h,   '2'  32h


IDEAL
MODEL small
STACK 100h
DATASEG

size1  equ 4
numstr db '4096$'   ; 1000h
vardec dw 10 

; --------------------------
; Your variables here
; --------------------------
CODESEG

proc       strnum   ; parameter is address of str number. result of call in dx
              push bp
              mov  bp,sp
              push bx 
              mov  di,[bp+4]
              mov  cx,size1
              mov  bx,1      ; (powers of 10 - 1,10,100,1000 etc.)
              xor  dx,dx
              xor  ax,ax
              add  di,cx
              dec  di

digits:
              mov  al,[di]
              cmp  al,'$'
              je   nextdigit
              sub  al,30h
              mov  ah,0
              push dx
              mul  bx        ;  dx:ax  =  ax*bx
              pop  dx
              add  dx,ax     ; collect sum of digits 
              mov  ax,bx
              push dx
              mul  [vardec]
              pop  dx
              mov  bx,ax
nextdigit:
              dec  di
              loop digits
              pop  bx
              pop  bp
              ret  2
endp      strnum

;--------------------------------------------------------------------



start:
	          mov ax, @data
	          mov ds, ax
              push offset  numstr
              call strnum    ; now dx has the result 
    		
exit:
	          mov ax, 4c00h
	          int 21h
END start


