News:

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

How to add

Started by john113, April 21, 2008, 01:18:23 AM

Previous topic - Next topic

john113

I was wondering how can you add two zero terminated decimal numbers together, and display them on the screen?

ex: 9+9=18

cobold

f. ex. like this


.data
szFirst db "9", 0
szSecond db "9", 0
n1 dd ?
n2 dd ?

.code
invoke atodw, ADDR szFirst ; convert first string to DWORD - result in eax
mov n1, eax ; move it to n1
invoke atodw, ADDR szSecond ; convert second string..
add eax, n1 ; add n1 to eax, result in eax
mov n2,eax ; mov it to n2
print str$(n2) ; display it



hth

john113

at last, I did most of it right except displaying it! ::) Thanks very much for your help  :U

raymond

That's fine if you have only one or a few digits to add. It would be quite different if you had 20-digit numbers (or longer) to handle. See the following if you are interested.

http://www.ray.masmcode.com/BCDtut.html

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com