~ruther/verilog-riscv-semestral-project

ref: 79c7be5c1c8ae2aea07f48d32abca650d24e8045 verilog-riscv-semestral-project/programs/gcd.c -rw-r--r-- 790 bytes
79c7be5c — Rutherther chore: remove unnecessary executable flags 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifdef unix
#include <stdio.h>
#endif

int int_remainder(int a, int b)
{
    if (b == 0) {
        return 0;
    }

    while (a >= b) {
        a -= b;
    }

    return a;
}

int gcd(int a, int b)
{
    int previous_r = b;

    int current_r;
    while ((current_r = int_remainder(a, previous_r)) != 0) {
        a = previous_r;
        previous_r = current_r;
    }

    return previous_r;
}

#ifdef unix
void main()
{
    int a, b;
    printf("a: ");
    scanf("%d", &a);
    printf("b: ");
    scanf("%d", &b);
    int res = gcd(a, b);
    printf("%d\n", res);
}
#else
void main()
{
    int* a_address = (int*)4;
    int* b_address = (int*)8;

    int a = *a_address;
    int b = *b_address;

    int res = gcd(a, b);

    int* result_address = 0;
    *result_address = res;
}
#endif
Do not follow this link