Using Windows 32 framework , write an assembly language program;
Write a recursive procedure to find the greatest
common divisor of
two non negative numbers. You should use Euclidean algorithm and
this is typically
discussed in CSC 230. Your procedure:
❼ Needs to follow cdecl protocol.
❼ Needs to take two parameters.
❼ Should return -1, if the parameters are negative.
❼ Should return gcd, if the parameters are non negative.
Your main procedure should do the followings.
❼ Read two integers using input macro.
❼ Call above gcd procedure after appropriately passing
parameters.
❼ Display an appropriate message using output macro if procedure
returns -1 or
❼ Display the valid result returned from your procedure using the
output macro.
Euclid Algorithm:
gcd(m, 0) =
m
gcd(m, n) = gcd(n,
m mod n)
1). ANSWER :
GIVENTHAT :
Assembly code for gcd of two numbers .(M,N).
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter the value of M = $'
PROMPT_2 DB 0DH,0AH,'Enter the value of N = $'
PROMPT_3 DB 0DH,0AH,'The GCD of M and N is = $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, PROMPT_1
MOV AH, 9
INT 21H
CALL INDEC
PUSH AX
LEA DX, PROMPT_2
MOV AH, 9
INT 21H
CALL INDEC
MOV BX, AX
POP AX
@REPEAT:
XOR DX, DX
DIV BX
CMP DX, 0
JE @END_LOOP
MOV AX, BX
MOV BX, DX
JMP @LOOP
@END_LOOP:
LEA DX, PROMPT_3
MOV AH, 9
INT 21H
MOV AX, BX
CALL OUTDEC
MOV AH, 4CH
INT 21H
MAIN ENDP
Get Answers For Free
Most questions answered within 1 hours.