现在的位置: 首页 > 综合 > 正文

欧几里得求两个整数最大公约数算法的汇编递归实现代码

2013年10月03日 ⁄ 综合 ⁄ 共 759字 ⁄ 字号 评论关闭

 《intel 汇编语言程序设计》第八章练习题

;程序的描述:求最大公约数算法的汇编递归实现,欧几里得算法又称辗转相除法
;作者:落叶树
;创建日期:
16:42 2007-7-30
;版本:
INCLUDE Irvine32.inc

.data

.code
main PROC
    mov eax,1000h
    mov ebx,100h
    call TwoIntnoRecursive_gcd  ;大写的被禁止了,晕
    call DumpRegs
    call Crlf
    exit
main ENDP

;其他子程序
TwoIntnoRecursive_gcd PROC
;参数:eax,ebx为求最大公约数的两个整数
;返回:edx为最大公约数
    push eax
    push ebx
    test eax,80000000h
    .
if Sign?
        neg eax   ;求绝对值
    .endif
    
    test ebx,80000000h
    .
if Sign?
        neg ebx    ;求绝对值
    .endif
    
    .
if eax<ebx
        xchg eax,ebx
    .elseif ebx
==0
        mov edx,eax   ;当余数为0,返回edx值
        jmp quit
    .endif

    mov edx,
0
    div ebx
    mov eax,ebx
    mov ebx,edx
    call TwoIntnoRecursive_gcd
    quit:
    pop ebx
    pop eax
    ret

TwoIntnoRecursive_gcd ENDP
END main

 

 

抱歉!评论已关闭.