File tree 2 files changed +32
-16
lines changed
2 files changed +32
-16
lines changed Original file line number Diff line number Diff line change
1
+ # RISC-V assembly program to print "Hello World!" to stdout.
2
+
1
3
.org 0
4
+ # Provide program starting address to linker
2
5
.global _start
3
6
4
- .data
5
-
6
- str: .ascii "Hello World!\n"
7
- .set str_size, .-str
8
-
9
7
/* newlib system calls */
10
8
.set SYSEXIT , 93
11
9
.set SYSWRITE, 64
12
10
13
- .text
11
+ .data
12
+ str: .ascii "Hello World!\n"
13
+ .set str_size, .-str
14
14
15
+ .text
15
16
_start:
16
- li a7, SYSWRITE
17
- li a0, 1
18
- la a1, str
19
- li a2, str_size
20
- ecall
21
-
22
- li a7, SYSEXIT
23
- add a0, x0, 0
24
- ecall
17
+ li t0, 0
18
+ li t1, 5
19
+
20
+ # dummy test for jal instruction
21
+ .L1:
22
+ jal x0, .L2
23
+ .L2:
24
+ nop
25
+
26
+ loop:
27
+ beq t0, t1, end
28
+
29
+ li a7, SYSWRITE # "write" syscall
30
+ li a0, 1 # 1 = standard output (stdout)
31
+ la a1, str # load address of hello string
32
+ li a2, str_size # length of hello string
33
+ ecall # invoke syscall to print the string
34
+ addi t0, t0, 1
35
+ j loop
36
+
37
+ end:
38
+ li a7, SYSEXIT # "exit" syscall
39
+ add a0, x0, 0 # Use 0 return code
40
+ ecall # invoke syscall to terminate the program
Original file line number Diff line number Diff line change 1
- OUTPUT_ARCH ( "riscv" )
1
+ OUTPUT_ARCH ("riscv")
2
2
ENTRY (_start )
3
3
4
4
SECTIONS
You can’t perform that action at this time.
0 commit comments