~ruther/verilog-riscv-semestral-project

ref: ee0204c8aee094b0d30256a61ba9400adb01dd5a verilog-riscv-semestral-project/programs/gcd.c -rwxr-xr-x 658 bytes
ee0204c8 — Rutherther feat: pass program to execute by parameter 1 year, 5 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