Synchronous exercises for programming in Windows assembly language (1)

Source: Internet
Author: User

<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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.