Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22037

How to print to console in Linux from RISC V assembly

$
0
0

I attempting to compile RISC V assembly in Linux using as and gcc.

The emulator is TinyEmu and busybox has all the utilities. TinyEmu

The image is diskimage-linux-riscv-2018-09-23.

I can get the program to compile, but nothing is printed on the console.

.section .text
.globl _start
_start:

    li a0, 0                    # stdout
1:  auipc a1, %pcrel_hi(msg)    # load msg(hi)
    addi a1, a1, %pcrel_lo(1b)  # load msg(lo)
    li a2, 12                   # length
    li a3, 0
    li a7, 64                   # _NR_sys_write
    ecall                       # system call

    li a0, 0
    li a1, 0
    li a2, 0
    li a3, 0
    li a7, 93                   # _NR_sys_exit
    ecall                       # system call

loop:
    j loop

.section .rodata
msg:   
    .string "Hello World\n"

I have tried several combinations of as and gcc calls, but the most recent is:

as -o hello.o hello.s
ld as -o hello.o hello.s

This creates a binary, but no console output.

So, what as, ld and/or gcc command will get an executable that can make the proper call to syscall to print to the console?

Also, where is the reference for syscalls in Linux on RISC V? (I have found x86 resources, but I haven't tested to see if they match per the syscall table).


Viewing all articles
Browse latest Browse all 22037

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>