Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to write a program in hmmm assembly that will take two user inputs and find the least common multiple of them....lines 00-07 calculate the greatest common denominator, and that part definitely works--it's the last few line I am having trouble with. Can you help me work this out?

LCM = """
00 read r1            #get n
01 read r2            #get m
02 jeqzn r2, 7       #jump to line 8
03 copy r3, r1      #save old n
04 copy r4, r2      #save old m
05 copy r1, r2      #set n = m
06 mod r2, r3, r2  #m = n_old % m
07 jumpn 2           #jump to line 2
08 mul r5, r3, r4    #n * m
09 div r6, r5, r1     #n * m / gcd(n, m)
10 write r1              #write lcm
11 halt
Updated 9-Apr-15 8:23am
BacchusBeale 8-Apr-15 20:10pm    
I don't know this language but line 2: "If rX = 0 then set program counter to address #" goes to line 7 and line 7 goes back again to line 2. Infinite loop?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900