DEV Community

loading...

Discussion on: How to build xv6-riscv on mac

Collapse
tingwei628 profile image
Tingwei Author

Here is a RISC-V "Hello World" example

Step 1: write rv-hello.s


.global _start                                                                                      

_start: addi  a0, x0, 1
        la    a1, helloworld
        addi  a2, x0, 13
        addi  a7, x0, 64
        ecall

        addi    a0, x0, 0
        addi    a7, x0, 93
        ecall

.data
helloworld:      .ascii “Hello World!\n” 
Enter fullscreen mode Exit fullscreen mode

Step2: assemble rv-hello.s and link

riscv64-unknown-elf-gcc -o rv-hello rv-hello.s -nostdlib -static
Enter fullscreen mode Exit fullscreen mode

Step3: run the program

riscv64-unknown-elf-run rv-hello
Enter fullscreen mode Exit fullscreen mode

// Hello World!