C语言描述该程序流程:
//辗转相除法 #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); while(a-b!=0) { if(a>b) { a=a-b; } else { b=b-a; } } printf("%d",a); }
汇编语言:
include irvine32.inc .data a dword ? b dword ? .code main proc call readint mov a,eax call readint mov b,eax mov eax,a mov ebx,b func: cmp eax,ebx jne compare ;如果不相等就跳转到compare,否则直接output输出 output: call writeint exit compare: jge jianfa ;如果a>b,则进行a-b sub ebx,eax ;否则进行b-a jmp func jianfa: sub eax,ebx jmp func main endp end main
运行结果: