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
|
.section .data
arr: .word 3, 5, 9, 33, 10, 59, 22, 95, 23, 24
.section .text
.globl _start
#
# a5 - Holds the current array index address
# a1 - The loop counter
# t4 - total elements in the array
# t1 - the index - actually used to calculate the next
# item, always the array member size, can be a loop invariant
# t2 - holds the new index address, I'm pretty sure this can use a5 again
get_largest_number:
la a5, arr
lw a0, (a5)
li a1, 1
li t4, 10
slli t1, a1, 2
for:
bge a1, t4, for_exit
add a5, a5, t1
lw t3, (a5)
blt t3, a0, skip
mv a0, t3
skip:
addi a1, a1, 1
j for
for_exit:
ret
_start:
call get_largest_number
li a7, 93
ecall
|