News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

printing number?

Started by HATEM, December 16, 2007, 07:35:27 PM

Previous topic - Next topic

HATEM

hello
i want to print the result of 400+700 by using loop but the problem is how i determain Determining the number of CX in loob look
to my program but i can't use Loop
        mov  cx,0     
        mov  bx,x
        add  bx,y   
        call   subs  ;dx=110
        mov  y,bx
        mov  bx,dx
        call   subs  ; dx=11
        mov  x,bx
        mov  bx,dx
        call   subs  ; dx=1
        mov  ah,2h 
        call   print 
        mov  dx,bx 
        call   print 
        mov  dx,x 
        call   print 
        mov  dx,y 
        call   print 
        mov  ah,4ch 
        int    21h 
subs proc near 
       mov dx,0 
       inc  cx
z:    sub  bx,10         
       inc   dx       
       cmp bx,9         
       jg z 
       ret 
subs  endp 
print proc near 
        add  dx,30h 
        int    21h 
        ret 
print  endp 

and i nedd a procedure print the result wich i can use it in all my program

Larry Hammick

It's not easy to get the _top_ decimal digit, and then the next smallest, and so on. But it is easy to get the bottom digit first, because DIV puts a remainder in dx.
(MASM 5.1 for DOS)ASSUME cs:code,ds:code,ss:stack

code segment
x dw 400
y dw 700

Go:
        push cs
        pop ds
        mov cx,10
        mov ax,x
        add ax,y
        call printax
        mov ah,4Ch
        int 21h

printax:
        mov dx,0
        div cx
        add dl,"0"
        push dx  ;save each digit on the stack
        cmp ax,0
        je short startprinting  ;when there are no more digits, print them in the opposite order
        call printax
startprinting:
        pop dx
        mov ah,2
        int 21h
        ret

code ENDS
stack segment para stack 'stack'
db 100h dup (?)
stack ends
END Go

HATEM

Thank you very much Larry Hammick   :U
and i have a quation can i save each digit in a TAble instead the stack?