forked from plctlab/riscv-operating-system-mooc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
63 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
/* | ||
* a0 --> a | ||
* a1 --> b | ||
* c <-- a0 | ||
*/ | ||
int foo(int a, int b) | ||
{ | ||
int sum = a + b; | ||
return sum; | ||
int c = a + b; | ||
return c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
# ASM call C | ||
|
||
.text # Define beginning of text section | ||
.global _start # Define entry _start | ||
.global foo # foo is a C function defined in test.c | ||
|
||
_start: | ||
la sp, stack_end # prepare stack for calling functions | ||
|
||
li a0, 1 | ||
li a1, 2 | ||
call foo | ||
|
||
stop: | ||
j stop # Infinite loop to stop execution | ||
|
||
stack_start: | ||
.rept 10 | ||
.word 0 | ||
.endr | ||
stack_end: | ||
|
||
.end # End of file | ||
# ASM call C | ||
|
||
.text # Define beginning of text section | ||
.global _start # Define entry _start | ||
.global foo # foo is a C function defined in test.c | ||
|
||
_start: | ||
la sp, stack_end # prepare stack for calling functions | ||
|
||
# RISC-V uses a0 ~ a7 to transfer parameters | ||
li a0, 1 | ||
li a1, 2 | ||
call foo | ||
# RISC-V uses a0 & a1 to transfer return value | ||
# check value of a0 | ||
|
||
stop: | ||
j stop # Infinite loop to stop execution | ||
|
||
nop # just for demo effect | ||
|
||
stack_start: | ||
.rept 10 | ||
.word 0 | ||
.endr | ||
stack_end: | ||
|
||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
int foo(int a, int b) | ||
{ | ||
int sum; | ||
asm volatile( | ||
"nop\n" | ||
int c; | ||
|
||
asm volatile ( | ||
"add %[sum], %[add1], %[add2]" | ||
:[sum]"=r"(c) | ||
:[add1]"r"(a), [add2]"r"(b) | ||
); | ||
|
||
/* | ||
asm volatile ( | ||
"add %0, %1, %2" | ||
:"=r"(sum) | ||
:"=r"(c) | ||
:"r"(a), "r"(b) | ||
); | ||
return sum; | ||
*/ | ||
return c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.