Hi
I am using the following code as part of a program to request a user to enter two separate intergers and then output the sum on the screen.
mov al, num1
add al, num2
mov result, al
When the two intergers are inputtted for example 1, 1 the output is the char 'b' instead of 2 and if 1, 2 is entered the output is char 'c' instead of the interger 3.
Can anyone explain what I am doing wrong?
Thanks
1 = 31h
2 = 32h
3 = 33h
31h + 32h = 63h
you have to convert your ascii number in numbers
I see...So if i enter two decimal numbers on the keyboard the computer stores them as hex.
1 = 31h and 2 = 32h which = 63h
So before I can out put a decimal on the screen I need to subtract 30h from the sum.
Just tried it and it works thanks.
Hi, to process numbers larger than 255, consider something like this:
.data?
szVal1 dd 12 dup (?)
szVal2 dd 12 dup (?)
nVal1 dd ?
nVal2 dd ?
szResult dd ?
.code
mov szVal1,chr$("12345678") ; put some ascii values in our
mov szVal2,chr$("87654321") ; two strings
invoke atodw,[szVal1] ; convert both to dwords, note
mov [nVal1],eax ; ADDR must not be used with szVal,
invoke atodw,[szVal2] ; even though these are strings
mov [nVal2],eax ; save second decimal value
add eax,[nVal1] ; "add" the second to the first
invoke dwtoa,eax,addr szResult ; convert this dword back to ascii
invoke MessageBox,0,addr szResult,0,MB_OK ; display it