#
# Risc-V Assembler program to print "Hello World!"
# to stdout.
#
# a0-a2 - parameters to linux function services
# a7 - linux function number
#
.global _start # Provide program starting address to linker
# Setup the parameters to print hello world
# and then call Linux to do it.
_start: addi a0, x0, 1 # 1 = StdOut
la a1, helloworld # load address of helloworld
addi a2, x0, 13 # length of our string
addi a7, x0, 64 # linux write system call
ecall # Call linux to output the string
# Setup the parameters to exit the program
# and then call Linux to do it.
addi a0, x0, 0 # Use 0 return code
addi a7, x0, 93 # Service command code 93 terminates
ecall # Call linux to terminate the program
.data
helloworld: .ascii "Hello World!\n"
root@ubuntu:~/riscv_learn/01_ecall# riscv64-linux-gnu-as -march=rv64imac -o hello.o hello.s
root@ubuntu:~/riscv_learn/01_ecall# riscv64-linux-gnu-ld -o hello hello.o
root@ubuntu:~/riscv_learn/01_ecall# riscv64-linux-gnu-objdump -d hello
hello: file format elf64-littleriscv
Disassembly of section .text:
00000000000100b0 <_start>:
100b0: 00100513 li a0,1
100b4: 00001597 auipc a1,0x1
100b8: 02058593 addi a1,a1,32 # 110d4 <helloworld>
100bc: 00d00613 li a2,13
100c0: 04000893 li a7,64
100c4: 00000073 ecall
100c8: 00000513 li a0,0
100cc: 05d00893 li a7,93
100d0: 00000073 ecall