title: Mars Mips Assembly
body: <p>Hello everyone im very new to mips assembly and my teacher gave us the following solution. The program basically finds the min and max vals in a array using the stack. I get completely lost especially using the stack since I cant visualize any of this. Please maybe explain the different lines in human language, I would greatly appreciate it!   </p>
  
  <pre><code>.data
  array:   .word  4, 10, -1, 8, 0, 22, 100, 100, -5, 45
  .text
  main:
  la   $a0, array
  li   $a1, 10
  jal  minmax
  j    exit
  minmax:
  addi $sp, $sp, -8
  sw   $a0, 0($sp)
  sw   $a1, 4($sp)
  lw   $v0, 0($a0)
  lw   $v1, 0($a0)
  addi $a1, $a1, -1
  next:
      ble  $a1, $zero, return
  addi $a0, $a0, 4
  addi $a1, $a1, -1
  lw   $t0, 0($a0)
  blt  $v0, $t0, max
  move $v0, $t0
  max:   
    bgt  $v1, $t0, next
  move $v1, $t0
  j    next
  return:  
  lw   $a0, 0($sp)
  lw   $a1, 4($sp)
  addi $sp, $sp, 8
  jr   $ra
  exit:
  </code></pre>