Incorrect value of the variable ans that stores the LCM of two numbers (8086 Program)
问题 Following is the code I wrote to find LCM of two numbers in EMU8086. When I ran it, I am getting value 0 in the Ans variable. .MODEL SMALL .DATA Num1 DW 250 Num2 DW 100 Ans DW ? .CODE MOV AX,@DATA MOV DS, AX MOV AX, Num1 MOV BX, Num2 MOV DX, 0000h NEXT: PUSH AX PUSH DX DIV BX CMP DX, 0000h JZ LAST POP DX POP AX ADD AX, Num1 JNC NEXT INC DX JMP NEXT LAST: POP Ans+2 POP Ans MOV AH, 4Ch INT 21h END 回答1: LCM(a, b) = a * b / GCD(a, b) Due to this equation, you can find GCD using Euclid's algorithm