12 what should go in

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t returns a pointer to local data that will go out of scope. (c) Line 8: A char* is given where a yarn was expected. (d) Line 9: A null terminator is returned instead of an int. (e) Nothing is wrong with this code. Section III: C- to- MIPS A Stanford student has attempted to convert some C code into MIPS. The original C code was: int add_all_the_nums(int* first_num, int num_count){ int sum = 0; for(int i=0; i < num_count; i++){ sum += first_num[i]; } return sum; } 4 The student’s solution was: Line Code ADD_ALL_NUMS: 1 add $t0,$0,$0 2 3 4 5 6 7 LOOP: beq lw add addi addi j 8 9 END: add $v0,$t0,$0 jr $ra $a1,$0,END $t1,0($a0) $t0,$t0,$t1 $a1,$a1,-1 $a0,$a0,1 LOOP As you can probably guess, this MIPS code has problems. 11. Which of the following changes will fix a problem with the code, assuming that the input is always valid? (a) change line 3 to lw $t1,4($a0) (b) change line 7 to jal LOOP (c) change line 6 to addi $a0,$a0,4 (d) change line 8 to or $v0,$t0,$0 (e) change line 5 to slt $a1,$a0,$a1 For the following two questions, we have partially encoded the instruction at line 2, beq $a1,$0,END into hex: opcode rs rt immediate 000100 ????? ????? ???? ???? ???? ???? 12. What should go in the rs field? (a) 00101 (b) 01001 (c) 00100 (d) 00001 (e) 00000 13. What should go in the immediate field (assuming no delayed branching)? (a) 1111 1111 1111 1011 (b) 0000 0000 0000 1100 (c) 0000 0000 0000 0110 (d) 0000 0000 0000 0101 (e) 0000 0000 0001 0100 5 CS61C Fall 2013 Midterm 14. Assume that the code was loaded into the 0x0 segment (the upper four bits of PC are a...
View Full Document

Ask a homework question - tutors are online