SHARE
TWEET

Untitled

a guest Aug 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int rmOdd(int *src, int n, int *dest)
  2. {
  3.    int i, j = 0;
  4.    for (i = 0; i < n; i++) {
  5.       if (src[i]%2 == 0) {
  6.          dest[j] = src[i];
  7.          j++;
  8.       }
  9.    }
  10.    return j;
  11. }
  12.      
  13. .text
  14.     .globl  rmOdd
  15. # params: src=$a0, n=$a1, dest=$a2
  16. rmOdd:
  17.     # prologue
  18.     addi    $sp, $sp, -4
  19.     sw  $fp, ($sp)
  20.     la  $fp, ($sp)
  21.     addi    $sp, $sp, -4
  22.     sw  $ra, ($sp)
  23.     addi    $sp, $sp, -4
  24.     sw  $s0, ($sp)
  25.     addi    $sp, $sp, -4
  26.     sw  $s1, ($sp)
  27.  
  28. # function body
  29.     move $t1, $a0   #src
  30.     move $t2, $a1   #n
  31.     move $t3, $a2   #dest
  32.     li   $t4, 1     #i = 1
  33.     li   $t5, 1     #j = 1
  34. loop_1:
  35.     bge $t4, $t2, end_loop1    #if i >= n
  36.     mul $t6, $t4, 4      #i = i*4
  37.     add $t6, $t6, $t1    #i = i*4+src
  38.     lw  $t6, ($t6)       #t4 = src[i]
  39.     rem $t7, $t6, 2      #if src[i] % 2 != 0
  40.     bnez $t7, i_increment
  41.  
  42.     mul $t8, $t5, 4     #j = j*4
  43.     add $t8, $t8, $t3   #j = j*4+dest
  44.     lw  $t8, ($t8)
  45.     move $t6, $t8       #src[i] = dest[j]
  46.     addi $t5, $t5, 1
  47. i_increment:
  48.     addi $t4, $t4, 1
  49.     j loop_1
  50. end_loop1:
  51.     move $v0, $t5
  52.  
  53. # epilogue
  54.     lw  $s1, ($sp)
  55.     addi    $sp, $sp, 4
  56.     lw  $s0, ($sp)
  57.     addi    $sp, $sp, 4
  58.     lw  $ra, ($sp)
  59.     addi    $sp, $sp, 4
  60.     lw  $fp, ($sp)
  61.     addi    $sp, $sp, 4
  62.     jr  $ra
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top