User Tools

Site Tools


riscv

Riscv - how to use prinf from assembler

The following link explains how to setup and run RiscV Debian in qemu on Linux in order to complete the assembler task below:-

https://www.codeproject.com/Tips/5383029/Run-Debian-RISC-V-In-QEMU-Virtual-Environment-For

This link was so useful, I have reproduced it here for future reference:- RiscV-Qemu-Debian

All work has been carried out using Ubuntu as the host for qemu which then runs Riscv Debian .

assemble with: as test2.s -o test2.o

then compile with: gcc test2.o -o test2

run with: ./test2

test2.s
.section .rodata
prompt: .asciz "Value of t0 = %ld and value of t1 = %ld\n"
.globl main
.section .text
main:
    addi    sp, sp, -8
    sd      ra, 0(sp)
    la      a0, prompt
    li      t0,44
    li      t1,88
    mv      a1, t0
    mv      a2, t1
    call    printf
    ld      ra, 0(sp)
    addi    sp, sp, 8
    ret
riscv.txt · Last modified: 2025/02/03 17:39 by me