submit hw2-2
This is not a partnership assignment -- hand in your own work, and don't collaborate with anyone else.
struct point { union { int i; double d; } x; union { int I; double d; } y; } p[10];Consider the following C code:
int i; for(i=0; i<10; i++) { p[i].x.i = 0; p[i].y.i = 0; }Copy and paste the following piece of MIPS code into your hw2-2.txt file. Fill in the blanks in the following translation of this C code into MIPS:
la $8, p # $8 points to p[0] addi $9, $8, ____ # $9 points to p[10] L1: bge $8, $9, L2 # done if past end of array sw ___, 0($8) # p[i].x.i = 0 sw ___, ___($8) # p[i].y.i = 0 addi $8, ____, ____ # i++ b L1 L2:
1 foo: 2 bnez $a0, L 3 beqz $a1, exit1 4 li $v0, 0 5 jr $ra 6 7 exit1: 8 li $v0, 1 9 jr $ra 10 11 L: 12 addiu $sp, $sp, -16 13 sw $ra, 12($sp) 14 sw $a0, 8($sp) 15 sw $a1, 4($sp) 16 17 addiu $a0, $a0, -1 18 jal foo 19 sw $v0, 0($sp) 20 lw $a0, 8($sp) 21 lw $a1, 4($sp) 22 addiu $a0, $a0, -1 23 addiu $a1, $a1, -1 24 jal foo 25 lw $t0, 0($sp) 26 addu $v0, $v0, $t0 27 28 lw $ra, 12($sp) 29 addiu $sp, $sp, 16 30 jr $ra int foo(int x, int y) { if (x==0 && y==0) /* Please fill in the rest of this code */ return 1; }