~ruther/verilog-riscv-semestral-project

ref: 32388b786d96e16d5264fe541d217ba5ca6b7084 verilog-riscv-semestral-project/programs/gcd.c -rwxr-xr-x 658 bytes
32388b78 — Rutherther feat: add support for loading and saving ram from disk 1 year, 6 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
#ifdef unix
#include <stdio.h>
#endif

int int_remainder(int a, int b) {
    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;
}

void main()
{
    int a = 1071;
    int b = 462;

    #ifdef unix
    printf("a: ");
    scanf("%d", &a);
    printf("b: ");
    scanf("%d", &b);
    #endif

    int res = gcd(a, b);

    #ifdef unix
    printf("%d\n", res);
    #else
    int* result_address = 0;
    *result_address = res;
    #endif

}
Do not follow this link