Hi forum,
I was trying to implement the GCD algorithm in Assembly, but something seems to be going wrong when the execution phase reaches the 'div' instruction. I get an integer overflow error but I dont see why!?! Below is my GCD proc.
;;;;;;;;;;;;;
.data?
x dword ?
y dword ?
;;;;;;;;;;;;;;;;;;
GCD proc uses eax ebx edx
mov eax, 0
mov edx, 0
do:
cmp y, 0
jna finish
mov eax, x
mov ebx, y
div ebx ; this is the troublesome line!!
mov x, ebx
mov y, edx
jmp do
finish:
ret
GCD endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The EDX reg contained 7FFE0304 at the start of the program. just before calling the GCD proc EDX contains 00405014. Using the msdev debugger, when i step through the code it stops at the div instruction with unhandled exception integer overflow error 0xC000095. Just after the error edx contains 00000004. As input i entered 1000 and 12 for x and y respectively.
I'm clueless!
Can somebody plz help me???
Kunal.
I was trying to implement the GCD algorithm in Assembly, but something seems to be going wrong when the execution phase reaches the 'div' instruction. I get an integer overflow error but I dont see why!?! Below is my GCD proc.
;;;;;;;;;;;;;
.data?
x dword ?
y dword ?
;;;;;;;;;;;;;;;;;;
GCD proc uses eax ebx edx
mov eax, 0
mov edx, 0
do:
cmp y, 0
jna finish
mov eax, x
mov ebx, y
div ebx ; this is the troublesome line!!
mov x, ebx
mov y, edx
jmp do
finish:
ret
GCD endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The EDX reg contained 7FFE0304 at the start of the program. just before calling the GCD proc EDX contains 00405014. Using the msdev debugger, when i step through the code it stops at the div instruction with unhandled exception integer overflow error 0xC000095. Just after the error edx contains 00000004. As input i entered 1000 and 12 for x and y respectively.
I'm clueless!
Can somebody plz help me???
Kunal.