Skip to content

Commit 864d67e

Browse files
update program
1 parent 3e25145 commit 864d67e

3 files changed

Lines changed: 35 additions & 44 deletions

File tree

programs/hello.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
__attribute__((naked)) void _start(void) {
2-
__asm__ volatile (
3-
"li sp, 0x8000\n" // top of 32KB RAM
2+
__asm__ volatile(
3+
"li sp, 0x8000\n" // top of 32KB RAM
44
"call main\n"
5-
"loop: j loop\n"
6-
);
5+
"loop: j loop\n");
76
}
87

98
int main() {
10-
volatile unsigned char* mem = (volatile unsigned char*)0x4000;
9+
volatile unsigned char* mem = (volatile unsigned char*)0x0;
1110
int counter = 0;
1211

1312
while (1) {
1413
counter++;
15-
mem[counter] = counter; // sb x1, 0(x2) — store counter byte
14+
mem[0x4000 * counter] = counter;
1615

1716
// busy-wait pause loop (~2000 iterations)
18-
for (int i = 0; i < 2000; i++) {
19-
__asm__("nop"); // prevent compiler from optimizing away
20-
}
17+
// for (int i = 0; i < 2000; i++) {
18+
// __asm__("nop"); // prevent compiler from optimizing away
19+
// }
2120
}
2221
}

programs/hello.hex

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,17 @@ fe010113
66
00112e23
77
00812c23
88
02010413
9-
000047b7
10-
fef42223
9+
fe042423
1110
fe042623
1211
fec42783
1312
00178793
1413
fef42623
1514
fec42783
16-
fe442703
17-
00f707b3
15+
00e79793
16+
00078713
17+
fe842783
18+
00e787b3
1819
fec42703
1920
0ff77713
2021
00e78023
21-
fe042423
22-
0140006f
23-
00000013
24-
fe842783
25-
00178793
26-
fef42423
27-
fe842703
28-
7cf00793
29-
fee7d4e3
30-
fb9ff06f
22+
fd5ff06f

programs/hello.s

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@
55
.attribute stack_align, 16
66
.text
77
.align 2
8+
.globl _start
9+
.type _start, @function
10+
_start:
11+
#APP
12+
# 2 "./programs/hello.c" 1
13+
li sp, 0x8000
14+
call main
15+
loop: j loop
16+
17+
# 0 "" 2
18+
#NO_APP
19+
nop
20+
.size _start, .-_start
21+
.align 2
822
.globl main
923
.type main, @function
1024
main:
1125
addi sp,sp,-32
1226
sw ra,28(sp)
1327
sw s0,24(sp)
1428
addi s0,sp,32
15-
li a5,16384
16-
sw a5,-28(s0)
29+
sw zero,-24(s0)
1730
sw zero,-20(s0)
18-
.L4:
31+
.L3:
1932
lw a5,-20(s0)
2033
addi a5,a5,1
2134
sw a5,-20(s0)
2235
lw a5,-20(s0)
23-
lw a4,-28(s0)
24-
add a5,a4,a5
36+
slli a5,a5,14
37+
mv a4,a5
38+
lw a5,-24(s0)
39+
add a5,a5,a4
2540
lw a4,-20(s0)
2641
andi a4,a4,0xff
2742
sb a4,0(a5)
28-
sw zero,-24(s0)
29-
j .L2
30-
.L3:
31-
#APP
32-
# 11 "./programs/hello.c" 1
33-
nop
34-
# 0 "" 2
35-
#NO_APP
36-
lw a5,-24(s0)
37-
addi a5,a5,1
38-
sw a5,-24(s0)
39-
.L2:
40-
lw a4,-24(s0)
41-
li a5,1999
42-
ble a4,a5,.L3
43-
j .L4
43+
j .L3
4444
.size main, .-main
4545
.ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 15.2.0"
4646
.section .note.GNU-stack,"",@progbits

0 commit comments

Comments
 (0)