Files
build-linux-system-from-scr…/package/opensbi/hello.s
2026-01-16 09:30:35 +08:00

80 lines
1.4 KiB
ArmAsm
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# hello.s - RISC-V 64 , "hello world!"
.section .text
.global _start
_start:
# 0x80000000 <- OpenSBI
# 0x80200000 <- hello.bin
# 0x80210000 <-
#
li sp, 0x80210000
#
call print_hello
# 退 qemu Ctrl+A X
1: j 1b
# "hello world!"
print_hello:
#
addi sp, sp, -8
sd ra, 0(sp)
#
la a0, hello_string
#
call puts
#
ld ra, 0(sp)
addi sp, sp, 8
ret
# void puts(char *str)
# a0:
puts:
#
addi sp, sp, -16
sd ra, 8(sp)
sd s0, 0(sp)
mv s0, a0 #
PRINT_LOOP:
#
lb a0, 0(s0)
beq a0, zero, PRINT_DONE # '\0'
#
call putc
#
addi s0, s0, 1
j PRINT_LOOP
PRINT_DONE:
#
ld s0, 0(sp)
ld ra, 8(sp)
addi sp, sp, 16
ret
# void putc(char c)
# a0:
putc:
# 使 SBI (console_putchar)
li a7, 0x01 # SBI_EXT_0_1_CONSOLE_PUTCHAR
ecall
ret
#
.section .rodata
hello_string:
.asciz "\nHello RISC-V world!\n"
# 4
.align 2