【复习】ARM编程

发布于 2021-05-27  428 次阅读


1.1+2+···+100

LDR R0,#100
LDR R1,#0
LOOP
ADD R1,R1,R0
SUBS R0,R0,#1
BNZ LOOP
  1. 最大公约数
    C语言:

    #include<stdio.h>
    int main()
    {
    int m, n, temp, i;
    printf("Input m & n:");
    scanf("%d%d", &m, &n);
    if(m<n)  /*比较大小,使得m中存储大数,n中存储小数*/
    { /*交换m和n的值*/
        temp=m;
        m=n;
        n=temp;
    }
    for(i=n; i>0; i--)  /*按照从大到小的顺序寻找满足条件的自然数*/
        if(m%i==0 && n%i==0)
        {/*输出满足条件的自然数并结束循环*/
            printf("The GCD of %d and %d is: %d\n", m, n, i);
            break;
        }
    
    return 0;
    }
MOV R1,#56
MOV R2,#49
GCD
CMP R1,R2
BEQ complete
BLT lessthan
SUB R1,R1,R2
B   GCD
lessthan
SUB R2,R2,R1
B   GCD
complete

擦肩而过的概率