Extremely new to MIPs assembly language -- I haven't been able to find a link that specifically tells you what a function is distinguished as in MIPS, examples of how we use jal, jr, etc..
It's very difficult to find out how these actions work -- My text book for this section of the course is very broad and assumes I already know the language and just outlines a code (under the assumption that I know exactly what the code means)
Hence, the book isn't helping me so I'm trying to practice on my own..
Anywho, in my class we wrote a simple array code which supposedly has a "function" in it.
My question is -- how do I know what is the "function" Below is a code we did in class -- it's supposed to output an array from 1 to 10.. I understand where it increments and such (addi) and why it's a 1 and 4 but I don't understand what $ra, jal , jr mean... but I'm assuming that these have something to do with what a "function" is
#Load an array and display
.data
.align 2
a1: .space 40
.text
.globl main
main:
la $s0, a1
jal loadArray
la $s0, a1# <- return here after function return
jal displayArray
# <- return here after 2nd function
exit:
li $v0, 10
syscall
displayArray:
#$ra = the address of line 14
li $t0, 1 #int i = 0
displayLoop: blt $t0, 11, display
#else
jr $ra
display:
lw $t0, ($s0) # a1[i] = i;
li $v0, 1
move $a0, $t0
syscall
#incremment i and array pointer
addi $t0, $t0, 1
addi $s0, $s0, 4
j displayLoop
loadArray:
#$ra = the address of line 14
li $t0, 1 #int i = 0
loadLoop: blt $t0, 11, load
#else
jr $ra
load:
sw $t0, ($s0) # a1[i] = i;
#incremment i and array pointer
addi $t0, $t0, 1
addi $s0, $s0, 4
j loadLoop
So this is the sample code but the only difference between this code and a usual code with just labels is the jump register and jump and link... Does that distinguish what is a function???
Sorry for the long wall of text -- TL;DR In MIPS, how do you know what is a "function" I know what a label is (obv.) but not a function...
This isn't as straight forward to me as it is in cpp or java lol.