need help in adding two 64bit numbers

good day guys,
i need your help with this, a program that adds two 64bit numbers and stores at the memory location GAMMA. The first 64bit number is located at the memory location ALPHA whle the other 64bit number is located at memory location BETA..

i got some hint with my friend's book, i think it's not complete..
i dont know where to begin.. please i need your help.. here's the
code

lea si,alpha
lea di,beta
lea bx,gamma

mov ax,[si]
mov dx,[di]
add ax,dx
mov [bx],ax
pushf

mov cl,03h
go:inc si
inc di
mov ax,[si]
mov dx,[di]
popf
adc ax,dx
mov [bx],ax
pushf
dec cl
jnz go

end

thanks, hoping for your kind reply..
[763 byte] By [yeahdude] at [2007-11-20 11:23:27]
# 1 Re: need help in adding two 64bit numbers
Hello Yeahdude,

There are two problems in your code.

1. You need to increase BX after each
mov [bx],ax
Otherwise first byte of GAMMA will have an incorrect value and the other three bytes will keep the value they had before adding 64-bit numbers. You're doing well with INC SI and INC DI, just include INC BX.

2. When loop is finished, being CX equal to zero, you should clean the stack, which at that point keeps the flags (see PUSHF opcode before DEC CL). This is particularly important if your routine is called by another part of program; not doing so will most likely result in crash. Therefore, just add POPF after "JNZ GO".

Note: It is suggested to inspect CF (Carry Flag) after addition to verify that there's no overflow or process it accordingly.

Good luck.

Iaki Viggers
iviggers at 2007-11-10 3:55:06 >
# 2 Re: need help in adding two 64bit numbers
hi iviggers,
thanks for that,
im going to try what you've said.. my friend is also doing this kind of program but instead of
64bit, he's input is 32bit. we are doing it together to make it fast for us to
finish the program.. here is his code, can i ask if this is the same with what
im doing?

mov si,0002h
mov ax,alpha
mov bx,beta
mov cx,alpha[si]
mov dx,beta[si]
add ax,bx
adc cx,dx
mov gamma,ax
mov gamma[si],cx

thanks for the help.. ^_^
yeahdude at 2007-11-10 3:56:10 >
# 3 Re: need help in adding two 64bit numbers
Well, you may need to test it, but I don't think that parts like "alpha[si]" are correct; that's OK in C syntax, not in assembler.
iviggers at 2007-11-10 3:57:06 >
# 4 Re: need help in adding two 64bit numbers
hello iviggers,

i'm having a problem with the hint ive posted, i can't run the program well. can you help me solve this using the code ive posted?

thanks in advance..
yeahdude at 2007-11-10 3:58:11 >
# 5 Re: need help in adding two 64bit numbers
One point was missing in previous postings: Since we're processing two bytes at a time (ADD AX,DX instead of ADD AL,DL), increase of DI, SI and BX must be done twice. Therefore code ADD SI|DI|BX,02h instead of INC SI|INC DI|INC BX.

Assembled with tasm:

.model small
.stack 20h
.data
alpha db 1h,2h,3h,4h
beta db 5h,6h,7h,8h
gamma db 0,0,0,0
.code
start:
mov ax,@data
mov ds,ax
mov es,ax
;;;;;;;;;;;;; Here begins your code
;; needed changes are in uppercase
lea si,alpha
lea di,beta
lea bx,gamma

mov ax,[si]
mov dx,[di]
add ax,dx
mov [bx],ax
pushf

mov cl,03h
go:
ADD SI,02h ;;instead of inc si, since we're processing two bytes at a time
ADD DI,02h ;; see above
ADD BX,02h ;; see above; we don't want to override first byte of buffer
mov ax,[si]
mov dx,[di]
popf
adc ax,dx
mov [bx],ax
pushf
dec cl
jnz go
;;;;;;;;; Here ends your code

popf ;; clean stack

;; no screen display, but you can debug and verify correct addition
lea si,gamma
cld
lodsw ;; get the two least-significant bytes of result
lodsw ;; get the two most-significant bytes of result
mov ah,4ch
int 21h
end start

See you.

Iaki
iviggers at 2007-11-10 3:59:10 >
# 6 Re: need help in adding two 64bit numbers
can you tell me how to display it? please i need it badly.. :(

thanks anyway, your're really nice..
yeahdude at 2007-11-10 4:00:11 >
# 7 Re: need help in adding two 64bit numbers
hi iviggers,
can you help me to display the input and output? please, i really need it..
sorry for asking too much, you're my only hope.. =(

thanks in advance
yeahdude at 2007-11-10 4:01:15 >
# 8 Re: need help in adding two 64bit numbers
hey iviggers,

ive already fixed my problem.. im sorry for asking too much from you
but you're really a big help..

thanks a lot dude! god bless! :)
yeahdude at 2007-11-10 4:02:11 >
# 9 Re: need help in adding two 64bit numbers
Hello Yeahdude,

I'm glad you got it. Good luck.
iviggers at 2007-11-10 4:03:11 >