I want to compute the arithmetic mean of 4 signed integers in RISC-V. My current implementation is below:
.globl mean
.text
main:
li a0 1
li a1 2
li a2 3
li a3 4
jal ra, mean
addi a1, a0, 0
addi a0, x0, 1
ecall # Print Result
addi a1, x0, '\n'
addi a0, x0, 11
ecall # Print newline
addi a0, x0, 10
ecall # Exit
mean:
add a0 a0, a1
add a1, a2, a3
add a0, a0, a1
srai a0, a0, 2
ret
I think I am close but i am unsure if i used div correctly to divide the values. I also am not sure if I returned the mean correctly for a0 and if I need to free up space after.
I also need to round down any non-integer values that are computed by the mean, but I have no idea how to do so.