-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.S
More file actions
50 lines (39 loc) · 1.01 KB
/
Copy pathbasic.S
File metadata and controls
50 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-License-Identifier: ISC
# SPDX-FileCopyrightText: 2026 Accemic Technologies GmbH
.section .text
.globl _start
# basic.S — minimal RV32I control-flow
#
# Bare-metal example.
# mtvec points to `hang` so that ECALL/traps terminate in a stable way.
_start:
# Point mtvec at `hang` (e.g. QEMU virt machine, no BIOS)
la t3, hang
csrw mtvec, t3
# --- 1) conditional branch (TAKEN) ---
li t0, 1
li t1, 1
beq t0, t1, 1f
nop
1: # --- 2) call + return ---
call foo
# --- 3) indirect branch (JALR) ---
la t2, target_indirect
jalr x0, t2, 0
target_indirect:
# --- 4) conditional branch (NOT TAKEN) ---
li t0, 0
li t1, 1
beq t0, t1, skipped # NOT TAKEN -> fall-through
exit:
# --- 5) exit ---
li a0, 0
li a7, 93 # SYS_exit (ecall)
ecall # trap via mtvec to hang
hang:
j hang
skipped:
j exit
foo:
li a0, 42
ret