First question: I know that by definition the instruction Beq has at first two registers and then a label where to jump to. However, when I run Mars compiler I get that for example: "beq $s6, 1, Lable" is running well. I would like for explanation if this command is still valid, and if not so, then why is it compiled.
Second question - for this question I have the following code:
psudo code:
Main:
{
Func(3,12,0x12)
}
Func1(a,b,c)
{
sum=a+b+c
Func2(sum,a,b,c)
Return sum
}
Func2(sum,a,b,c)
{
sum=sum*(a+b+c)
Return (sum+1)
}
Main:
addi $a0, $0, 3 #first function input a0=3
addi $a1, $0, 12 #second function input a1=12
addi $a2, $0, 0x12 #third function input a2=0x12
jal Func1 #jump to function1 with those input virables.
add $s2 $0, $v0 #store the result of func1 at $s2.
j break #go to break.
Func1:
addi $sp, $sp, -16 #allocate memory for 4 registers
sw $a2, -12($sp) #restore a2 = c
sw $a1, -8($sp) #restore a1 = b
sw $a0, -4($sp) #restore a0 = a
sw $ra, 0($sp) #restore return address.
add $t0,$a0,$a1 #t0=a+b
add $t0,$t0,$a2 #t0+=c
add $a0, $0, $t0 #store the result of a+b+c at $a0.
lw $t1, -4($sp) #restore t1=a
add $a1, $0, $t1 #a1=t1
lw $t2, -8($sp) #restore t1=b
add $a2, $0, $t2 #a1=t2
lw $t3, -12($sp) #restore t1=c
add $a3, $0, $t3 #a1=t3
jal Func2 #jump to func2 with the input numbers a0,a1,a2,a3.
lw $ra, 0($sp) #change the return adress to the main function calling.
addi $sp, $sp, 16 #deallocate memory.
jr $ra #return
Func2:
add $t0, $a1, $a2 #t0=a+b
add $t0, $t0, $a3 #t0+=c
mult $a0, $t0 #sum*(a+b+c)
mflo $a0 #storing result in $a0
addi $v0,$a0,1 #storing result+1 at the return function variable $v0
jr $ra #return
break:
Now is this code valid? because it is complied too in Mars, however, I have noticed that both storing the word and loading, it is with - instead of +, is it valid considering MIPS instructions? Thanks!