| 1 |
# |
| 2 |
# Risc-V Assembler program to print "Hello World!" |
| 3 |
# to stdout. |
| 4 |
# |
| 5 |
# a0-a2 - parameters to linux function services |
| 6 |
# a7 - linux function number |
| 7 |
# |
| 8 |
|
| 9 |
.global _start # Provide program starting address to linker |
| 10 |
|
| 11 |
# Setup the parameters to print hello world |
| 12 |
# and then call Linux to do it. |
| 13 |
|
| 14 |
_start: addi a0, x0, 1 # 1 = StdOut |
| 15 |
la a1, helloworld # load address of helloworld |
| 16 |
addi a2, x0, 13 # length of our string |
| 17 |
addi a7, x0, 64 # linux write system call |
| 18 |
ecall # Call linux to output the string |
| 19 |
|
| 20 |
# Setup the parameters to exit the program |
| 21 |
# and then call Linux to do it. |
| 22 |
|
| 23 |
addi a0, x0, 0 # Use 0 return code |
| 24 |
addi a7, x0, 93 # Service command code 93 terminates |
| 25 |
ecall # Call linux to terminate the program |
| 26 |
|
| 27 |
.data |
| 28 |
helloworld: .ascii "Hello World!\n" |
| 29 |
|
| 30 |
# From https://smist08.wordpress.com/2019/09/07/risc-v-assembly-language-hello-world/ |
| 31 |
|