rve/example/example.c

34 lines
662 B
C

#include "printf.h"
typedef unsigned long long uint64_t;
typedef unsigned long uint32_t;
#define MTIME_BASE 0x0200BFF8
uint64_t read_mtime_atomic() {
uint32_t upper1, lower, upper2;
do {
upper1 = *(uint32_t*)(MTIME_BASE + 4);
lower = *(uint32_t*)(MTIME_BASE);
upper2 = *(uint32_t*)(MTIME_BASE + 4);
} while (upper1 != upper2); // Repeat if upper changed during the process
return ((uint64_t)upper1 << 32) | lower;
}
int fact(int n) {
if (n == 0)
return 1;
return n * fact(n-1);
}
int main() {
int n = 8;
int res = fact(8);
printf("sizeof(long) = %d\n", sizeof(long long));
printf("%d! = %d\n", n, res);
return 0;
}