<Windows assembly language programming> Exercise 17: see program C in the following section to calculate the maximum common approx. of A and B.
; Unsigned int gcd (unsigned int A, unsigned int B)
;{
; If (A = 0 & B = 0)
; B = 1;
; Else if (B = 0)
; B =;
; Else if (! = 0)
; While (! = B)
;{
; If (A <B)
; B-=;
; Else
; A-= B;
;}
; Return B;
;}
; 2006-12-12 Gao yuhan
; The number of processes in the program is not considered.
. 386
. Model flat, stdcall
Option Casemap: None
Includelib/masm32/lib/msvcrt. Lib
Printf proto C: DWORD,: vararg
. Data
Dtemp1 DWORD 91; temporary variable, used to store the input value.
Dtemp2 DWORD 49; temporary variable, used to store the input value B.
Szfmt byte 'maximum common divisor: % d', 0ah, 0
. Code
Start:
CMP dtemp1, 0
Jle B10; dtemp1 <= 0
CMP dtemp2, 0
Jle B10; dtemp2 <= 0
CMP dtemp1, 0
JG B30; dtemp1> 0
JMP b60; ended.
B10:
MoV dtemp2, 1
JMP b60
B30:
MoV eax, dtemp1
CMP eax, dtemp2
Je b60; dtemp1! = Dtemp2
JG B50; dtemp1> dtemp2
Sub dtemp2, eax; B-=
JMP B30
B50:
Sub eax, dtemp2; A-= B
MoV dtemp1, eax
JMP B30
B60:
Invoke printf, offset szfmt, dtemp2
RET
End start