#============================================================= # procedure1.s # - Demonstrates simple procedure and use of the sp # by printing an array of integers #============================================================= .data # Data declarations go here A: .word 5,4,3,2,1 length: .word 5 .text # The section where your code lives .globl main main: la $a0, A # a0 is A's address la $t0, length lw $a1, 0($t0) # a1 is the length of A jal printArray exit: li $v0,10 # Syscall for exit syscall printArray: addi $sp, $sp, -4 # Grow the stack down to hold caller's $s0 sw $s0, 0($sp) add $s0, $a0, $zero # s0 is now the address of A add $t0, $zero, $zero # temp registers not preserved by callee paLoop: beq $t0, $a1, paExit # If equal, jump to procedure exit lw $a0, 0($s0) # Take the t0-th array element li $v0, 1 syscall # Code for print integer addi $s0, $s0, 4 # Increment array address addi $t0, $t0, 1 j paLoop # Looping paExit: lw $s0, 0($sp) # restore the caller's registers addi $sp, $sp, 4 jr $ra # jump to next instruction in main