Blame


1 6bf04703 2024-04-05 benni .section .rodata
2 6bf04703 2024-04-05 benni fmt: .asciz "Hello World\n"
3 6bf04703 2024-04-05 benni ifmt: .asciz "%d\n"
4 6bf04703 2024-04-05 benni
5 6bf04703 2024-04-05 benni .section .data
6 6bf04703 2024-04-05 benni arr: .dword 1, 2, 3, 4, 5
7 6bf04703 2024-04-05 benni
8 6bf04703 2024-04-05 benni .section .text
9 6bf04703 2024-04-05 benni .global main
10 6bf04703 2024-04-05 benni main:
11 6bf04703 2024-04-05 benni addi sp, sp, -16
12 6bf04703 2024-04-05 benni sd s0, 8(sp)
13 6bf04703 2024-04-05 benni sd ra, 0(sp)
14 6bf04703 2024-04-05 benni
15 6bf04703 2024-04-05 benni jal hello
16 6bf04703 2024-04-05 benni
17 6bf04703 2024-04-05 benni jal printarr
18 6bf04703 2024-04-05 benni jal nl
19 6bf04703 2024-04-05 benni
20 6bf04703 2024-04-05 benni la a0, arr
21 6bf04703 2024-04-05 benni li a1, 1
22 6bf04703 2024-04-05 benni jal swap
23 6bf04703 2024-04-05 benni
24 6bf04703 2024-04-05 benni jal printarr
25 6bf04703 2024-04-05 benni
26 6bf04703 2024-04-05 benni jal nl
27 6bf04703 2024-04-05 benni
28 6bf04703 2024-04-05 benni la a0, arr
29 6bf04703 2024-04-05 benni li a1, 0
30 6bf04703 2024-04-05 benni jal avg
31 6bf04703 2024-04-05 benni mv s0, a0
32 6bf04703 2024-04-05 benni jal print
33 6bf04703 2024-04-05 benni
34 6bf04703 2024-04-05 benni mv a0, s0
35 6bf04703 2024-04-05 benni jal even
36 6bf04703 2024-04-05 benni jal print
37 6bf04703 2024-04-05 benni
38 6bf04703 2024-04-05 benni mv a0, zero
39 6bf04703 2024-04-05 benni ld ra, 0(sp)
40 6bf04703 2024-04-05 benni ld s0, 8(sp)
41 6bf04703 2024-04-05 benni addi sp, sp, 16
42 6bf04703 2024-04-05 benni ret
43 6bf04703 2024-04-05 benni
44 6bf04703 2024-04-05 benni // void hello (void);
45 6bf04703 2024-04-05 benni hello:
46 6bf04703 2024-04-05 benni la a0, fmt
47 6bf04703 2024-04-05 benni j printf
48 6bf04703 2024-04-05 benni
49 6bf04703 2024-04-05 benni // void nl (void);
50 6bf04703 2024-04-05 benni nl:
51 6bf04703 2024-04-05 benni li a0, 10
52 6bf04703 2024-04-05 benni j putchar
53 6bf04703 2024-04-05 benni
54 6bf04703 2024-04-05 benni // void print (int);
55 6bf04703 2024-04-05 benni print:
56 6bf04703 2024-04-05 benni addi sp, sp, -8
57 6bf04703 2024-04-05 benni sd ra, 0(sp)
58 6bf04703 2024-04-05 benni
59 6bf04703 2024-04-05 benni mv a1, a0
60 6bf04703 2024-04-05 benni la a0, ifmt
61 6bf04703 2024-04-05 benni jal printf
62 6bf04703 2024-04-05 benni
63 6bf04703 2024-04-05 benni ld ra, 0(sp)
64 6bf04703 2024-04-05 benni addi sp, sp, 8
65 6bf04703 2024-04-05 benni ret
66 6bf04703 2024-04-05 benni
67 6bf04703 2024-04-05 benni // void printarr (void);
68 6bf04703 2024-04-05 benni printarr:
69 6bf04703 2024-04-05 benni addi sp, sp, -32
70 6bf04703 2024-04-05 benni sd ra, 16(sp)
71 6bf04703 2024-04-05 benni sd s0, 8(sp)
72 6bf04703 2024-04-05 benni sd s1, 0(sp)
73 6bf04703 2024-04-05 benni
74 6bf04703 2024-04-05 benni la s0, arr
75 6bf04703 2024-04-05 benni mv s1, zero
76 6bf04703 2024-04-05 benni
77 6bf04703 2024-04-05 benni ploop:
78 6bf04703 2024-04-05 benni add a0, s0, s1
79 6bf04703 2024-04-05 benni ld a0, 0(a0)
80 6bf04703 2024-04-05 benni jal print
81 6bf04703 2024-04-05 benni
82 6bf04703 2024-04-05 benni addi s1, s1, 8
83 6bf04703 2024-04-05 benni li t0, (5 * 8)
84 6bf04703 2024-04-05 benni bne s1, t0, ploop
85 6bf04703 2024-04-05 benni
86 6bf04703 2024-04-05 benni
87 6bf04703 2024-04-05 benni ld s1, 0(sp)
88 6bf04703 2024-04-05 benni ld s0, 8(sp)
89 6bf04703 2024-04-05 benni ld ra, 16(sp)
90 6bf04703 2024-04-05 benni addi sp, sp, 32
91 6bf04703 2024-04-05 benni ret
92 6bf04703 2024-04-05 benni
93 6bf04703 2024-04-05 benni // void swap (long *v, size_t n);
94 6bf04703 2024-04-05 benni swap:
95 6bf04703 2024-04-05 benni slli a1, a1, 3
96 6bf04703 2024-04-05 benni add t0, a0, a1
97 6bf04703 2024-04-05 benni ld t1, 0(t0)
98 6bf04703 2024-04-05 benni ld t2, 8(t0)
99 6bf04703 2024-04-05 benni sd t2, 0(t0)
100 6bf04703 2024-04-05 benni sd t1, 8(t0)
101 6bf04703 2024-04-05 benni ret
102 6bf04703 2024-04-05 benni
103 6bf04703 2024-04-05 benni // long avg(long *v, size_t n);
104 6bf04703 2024-04-05 benni avg:
105 6bf04703 2024-04-05 benni slli a1, a1, 3
106 6bf04703 2024-04-05 benni add a0, a0, a1
107 6bf04703 2024-04-05 benni ld t0, 0(a0)
108 6bf04703 2024-04-05 benni ld t1, 8(a0)
109 6bf04703 2024-04-05 benni add a0, t0, t1
110 6bf04703 2024-04-05 benni srli a0, a0, 1
111 6bf04703 2024-04-05 benni ret
112 6bf04703 2024-04-05 benni
113 6bf04703 2024-04-05 benni // bool even(long);
114 6bf04703 2024-04-05 benni even:
115 6bf04703 2024-04-05 benni andi a0, a0, 1
116 6bf04703 2024-04-05 benni xor a0, a0, 1
117 6bf04703 2024-04-05 benni ret