• API
• FAQ
• Tools
• Archive
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
19.     sw  \$fp, (\$sp)
20.     la  \$fp, (\$sp)
22.     sw  \$ra, (\$sp)
24.     sw  \$s0, (\$sp)
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]
47. i_increment:
49.     j loop_1
50. end_loop1:
51.     move \$v0, \$t5
52.
53. # epilogue
54.     lw  \$s1, (\$sp)