hapter 8 Irvine book, When I compiled this code I get the following errors ;Greatest Common Divisor Comment ! Write a recursive implementation of Euclid’s algorithm for finding the greatest common divisor (GCD) of two integers. Descriptions of this algorithm are available in algebra books and on the Web. Write a test program that calls your GCD procedure five times, using the following pairs of integers: (5,20), (24,18), (11,7), (432,226), (26,13). After each procedure call, display the GCD. ! INCLUDE Irvine32.inc CalcGcd PROTO,int1:DWORD, int2:DWORD .data array SDWORD 5,20,24,18,11,7,438,226,26,13 str1 BYTE "Greatest common divisor is: ",0 .code main PROC mov ecx,LENGTHOF array / 2 mov esi,OFFSET array L1: INVOKE CalcGcd,[esi],[esi+4] mov edx,OFFSET str1 call WriteString call WriteDec call Crlf add esi,TYPE array * 2 loop L1 exit main ENDP ;--------------------------------------------- CalcGcd PROC, int1:DWORD, int2:DWORD ; ; Calculate the greatest common divisor, of two ; nonnegative integers, using Euclid's algrithm. ; Implemented using recursion. ; Receives: int1, int2 ; Returns: EAX = Greatest common divisor ;--------------------------------------------- ;Write your code here ;.GCD: ;following is the function for GCD .data pair1 QWORD 53 pair2 QWORD 17 .code ;main proc ; (5,20) mov RDX,0 mov RAX,5 mov RBX,20 push RAX push RBX call Gcd_Two_Numbers ; (24,18) mov RDX,0 mov RAX,24 mov RBX,18 push RAX push RBX call Gcd_Two_Numbers ; (11,7) mov RDX,0 mov RAX,11 mov RBX,7 push RAX push RBX call Gcd_Two_Numbers ; (432,226) mov RDX,0 mov RAX,432 mov RBX,226 push RAX push RBX call Gcd_Two_Numbers ; (26,13) mov RDX,0 mov RAX,26 mov RBX,13 push RAX push RBX call Gcd_Two_Numbers CALL ExitProcess ;main endp ;***** This function Find the GCD of Two No... ***** Gcd_Two_Numbers proc enter 0,0 mov RDX,0 mov RAX,[rbp+24] mov RBX,[rbp+16] DIV RBX cmp RDX,0 jz Lable push RBX push RDX call Gcd_Two_Numbers Lable: leave ret 8 ;Gcd_Two_Numbers endp end CalcGcd ENDP END main I get the following errors 1>------ Build started: Project: Project7, Configuration: Debug Win32 ------ 1>Assembling AddPacked.asm... 1>AddPacked.asm(92): error A2144: cannot nest procedures 1>AddPacked.asm(111): fatal error A1010: unmatched block nesting : Gcd_Two_Numbers 1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\AddPacked.obj" /I "c:\Irvine" /W3 /errorReport:prompt /TaAddPacked.asm" exited with code 1. 1>Done building project "Project7.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Chapter 8 Irvine book, When I compiled this code I get the following errors
;Greatest Common Divisor
Comment !
Write a recursive implementation of Euclid’s
the greatest common divisor (GCD) of two integers. Descriptions of
this algorithm are available in algebra books and on the Web. Write
a test program that calls your GCD procedure five times, using the
following pairs of integers: (5,20), (24,18), (11,7), (432,226),
(26,13). After each procedure call, display the GCD.
!
INCLUDE Irvine32.inc
CalcGcd PROTO,int1:DWORD, int2:DWORD
.data
array SDWORD 5,20,24,18,11,7,438,226,26,13
str1 BYTE "Greatest common divisor is: ",0
.code
main PROC
mov ecx,LENGTHOF array / 2
mov esi,OFFSET array
L1: INVOKE CalcGcd,[esi],[esi+4]
mov edx,OFFSET str1
call WriteString
call WriteDec
call Crlf
add esi,TYPE array * 2
loop L1
exit
main ENDP
;---------------------------------------------
CalcGcd PROC,
int1:DWORD, int2:DWORD
;
; Calculate the greatest common divisor, of two
; nonnegative integers, using Euclid's algrithm.
; Implemented using recursion.
; Receives: int1, int2
; Returns: EAX = Greatest common divisor
;---------------------------------------------
;Write your code here
;.GCD: ;following is the function for GCD
.data
pair1 QWORD 53
pair2 QWORD 17
.code
;main proc
; (5,20)
mov RDX,0
mov RAX,5
mov RBX,20
push RAX
push RBX
call Gcd_Two_Numbers
; (24,18)
mov RDX,0
mov RAX,24
mov RBX,18
push RAX
push RBX
call Gcd_Two_Numbers
; (11,7)
mov RDX,0
mov RAX,11
mov RBX,7
push RAX
push RBX
call Gcd_Two_Numbers
; (432,226)
mov RDX,0
mov RAX,432
mov RBX,226
push RAX
push RBX
call Gcd_Two_Numbers
; (26,13)
mov RDX,0
mov RAX,26
mov RBX,13
push RAX
push RBX
call Gcd_Two_Numbers
CALL ExitProcess
;main endp
;***** This function Find the GCD of Two No... *****
Gcd_Two_Numbers proc
enter 0,0
mov RDX,0
mov RAX,[rbp+24]
mov RBX,[rbp+16]
DIV RBX
cmp RDX,0
jz Lable
push RBX
push RDX
call Gcd_Two_Numbers
Lable:
leave
ret 8
;Gcd_Two_Numbers endp
end
CalcGcd ENDP
END main
I get the following errors
1>------ Build started: Project: Project7, Configuration: Debug Win32 ------
1>Assembling AddPacked.asm...
1>AddPacked.asm(92): error A2144: cannot nest procedures
1>AddPacked.asm(111): fatal error A1010: unmatched block nesting : Gcd_Two_Numbers
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\AddPacked.obj" /I "c:\Irvine" /W3 /errorReport:prompt /TaAddPacked.asm" exited with code 1.
1>Done building project "Project7.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images