forked from Github_Repos/cvw
Added inline assembly to simple
This commit is contained in:
parent
02f6030c02
commit
10921accdb
@ -9,7 +9,7 @@ $(TARGET): $(TARGET).c Makefile
|
|||||||
-fno-builtin-printf -fno-tree-loop-distribute-patterns \
|
-fno-builtin-printf -fno-tree-loop-distribute-patterns \
|
||||||
-static -nostdlib -nostartfiles -lm -lgcc -T../common/test.ld \
|
-static -nostdlib -nostartfiles -lm -lgcc -T../common/test.ld \
|
||||||
-I../common \
|
-I../common \
|
||||||
-O $(TARGET).c \
|
-O0 $(TARGET).c \
|
||||||
../common/crt.S ../common/syscalls.c
|
../common/crt.S ../common/syscalls.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -2,20 +2,34 @@
|
|||||||
// David_Harris@hmc.edu 24 December 2021
|
// David_Harris@hmc.edu 24 December 2021
|
||||||
// Simple illustration of compiling C code
|
// Simple illustration of compiling C code
|
||||||
|
|
||||||
#include <stdio.h>
|
//#include <stdio.h>
|
||||||
|
#include "util.h"
|
||||||
|
extern int printf(const char* fmt, ...);
|
||||||
|
|
||||||
long sum(long N) {
|
long sum(long N) {
|
||||||
long result, i;
|
/* long result, i;
|
||||||
result = 0;
|
result = 0;
|
||||||
for (i=1; i<=N; i++) {
|
for (i=1; i<=N; i++) {
|
||||||
result = result + i;
|
result = result + i;
|
||||||
}
|
}
|
||||||
return result;
|
return result; */
|
||||||
|
|
||||||
|
int a;
|
||||||
|
// asm volatile ("li s0, 10;");
|
||||||
|
asm volatile(
|
||||||
|
"li %0, 10"
|
||||||
|
// "csrrs %0, 0xF14, zero" //CSSRS rd, mhartid, 0
|
||||||
|
: "=r"(a) //output
|
||||||
|
: //input
|
||||||
|
: //clobbered
|
||||||
|
);
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
long s;
|
int s[1], expected[1];
|
||||||
s = sum(4);
|
s[0] = sum(4);
|
||||||
printf("s = %ld\n", s);
|
printf("s = %d\n", s[0]);
|
||||||
return 0; // 0 means success
|
expected[0] = 10;
|
||||||
|
return verify(1, s, expected); // 0 means success
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user