SHARE
TWEET

Untitled

a guest Apr 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. A: .word 2:2
  3.  
  4. .text
  5. main:
  6.     la $t3, A # address for A
  7.     addi $t4, $zero, 48 #counter max
  8.     addi $t5, $zero, 0 #offset
  9.     addi $t8, $zero, 0
  10.  
  11. LOOP:
  12.     beq $t4, $t5, END
  13.     add $t6, $t3, $t5 # holds address of A[i]
  14.     lw $t7, 0($t6) # gets value of A[i]
  15.     # push to stack
  16.     addi $sp, $sp -4
  17.     sw $t7, 0($sp)
  18.  
  19.     jal myfunc
  20.  
  21.     lw $t7, 0($sp)
  22.     addi $sp, $sp, 4
  23.  
  24.     add $t8, $t8, $t7
  25.     addi $t5, $t5, 4
  26.  
  27.     j LOOP
  28.  
  29. myfunc:
  30.     # pull from stack
  31.     lw $t0, 0($sp)
  32.     addi $sp, $sp, 4
  33.     addi $t1, $zero, 2
  34.     div $t0, $t1
  35.     mfhi $t0
  36.     beq $t0, $zero, LABEL1
  37.         add $t2, $zero, $zero
  38.         j LABEL2
  39.  
  40. LABEL1:
  41.     addi $t2, $zero, 1
  42.  
  43. LABEL2:
  44.     addi $sp, $sp, -4
  45.     sw $t2, 0($sp)
  46.     jr $ra
  47.  
  48. END:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top