2
GetLCM PROC
tryAgain:
   mov bx, 0
   inc Multiple
   mov ax, UserInputNum1              ;Move UserInputNum1 to the 16 bit Register
   mov bx, Multiple
   div bx                             ;<-------Error here
   cmp dx,0                           ;If dx is not zero then there is a remainder
   jne tryAgain                       ;If not equal jump
ret
GetLCM ENDP

I keep getting a integer overflow error when trying to div these two numbers. It breaks when i try to use div.

I am trying to find the least common multiple of two numbers entered by the user. I decided to try to divide each number to find prime numbers first then compare each time one is found to the other number the user entered. Of course I would be doing both numbers at the same time, but as of now I am trying to just get past this error.

This is only my fifth week in ASM so I am a little confuse why this is happening. Also I would like to add that I would also like to make this work for 32bit numbers as well. My idea is to use pointers. Is this a good way to do this? Thanks for any help!

James Leshko
  • 173
  • 1
  • 3
  • 16
  • 1
    Just an algorithmic remark: `lcm(a,b) = a*b/gcd(a,b)`, that's _much_ faster than finding primes dividing either of the numbers. – Daniel Fischer Nov 15 '12 at 03:39
  • In order to do assembly, you need to have your architecture's manuals handy, e.g. [Intel's x86 Instruction Set Reference](http://download.intel.com/design/intarch/manuals/24319101.pdf). 16-bit `DIV` works on `DX:AX`. Your `DX` has not been set. To do 32-bit, just reference 32-bit register mnemonics, `EAX`, `ECX`, etc. – A. Webb Nov 15 '12 at 03:39
  • Again someone who forgot that `div` is double-width. Apparently it doesn't show up in the suggested questions when asking about it. Can't something be done about that? – harold Nov 15 '12 at 09:10

2 Answers2

5

xor dx, dx somewhere before your div

Gunner
  • 5,780
  • 2
  • 25
  • 40
2

Read up on the div instruction again. What is divided by what? You are missing to set one of the operands to some sensible value.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47