EE553 Quiz August 8 2015 Name ____________________________________ Student ID __________________ 1. Encode MIPS instruction sra $8, $9, 4 a) 00084902 b) 00084903 c) 00094100 d) 00094102 e) 00094103 2. Disassemble MIPS instruction 01484807 a) sltu $10, $9, $8 b) bltz $8, 1f c) lb $8, ($8) d) srav $9, $8, $10 e) or $8, $8, $8 3. What is the result of the following MIPS program execution? li $8, 12 li $9, 13 li $10, 14 addu $10, $8, $9 a) $8=0x0000000c, $9=0x0000000d, $10=00000019 b) $8=0x0000000c, $9=0x0000001a, $10=0000000e c) $8=0x00000014, $9=0x00000012, $10=00000019 d) $8=0x0000001b, $9=0x0000000d, $10=0000000e e) $8=0x0000000c, $9=0x0000001a, $10=0000000e 4. What is the result of the following MIPS program execution? .data a3: .word 0x12345678 .word 0x9abcdef0 .word 0x11111111 .word 0x22222222 .word 0x33333333 .text ld3: la $8, a3 or $9, $8, $8 lw $8, 4 ($8) sb $8, ($9) a) $8=0x00000056 b) $8=0x12345678 c) $8=0x00000012 d) $8=0xffffff9a e) $8=0x9abcdef0 5. What is the result of the following MIPS program execution? bltz1: li $8, 12 bltz $8, 1f li $10, 14 li $10, 15 1: a) $10 = 12 b) $10 = 13 c) $10 = 14 d) $10 = 15 e) $10 = 0x1f 6. What is the purpose of using program stack in assembly (and any other) programming? a) Stack is needed to store return addresses for the nested function calls b) Stack is used to pass function parameters when there is no place on registers c) Stack is used to allocate space for temporary variables when there is no place on registers d) Stack is used to save some temporary registers when calling a function e) All the above 7. What MIPS assembly code corresponds to the following C code? int f (int a, int b) { int i, sum; for (i = a; i <= b; i++) sum += i; return sum; } ////////// a ////////// f: li $3,1 beq $4,$3,.L3 li $3,2 beq $4,$3,.L6 nop bne $4,$0,.L9 nop lw $2,%gp_rel(a)($28) j $31 sltu $2,$0,$2 .L3: li $2,2 lw $3,%gp_rel(b)($28) j $31 movz $2,$0,$3 .L6: move $2,$0 .L9: j $31 nop ////////// b ////////// f: addiu $sp,$sp,-24 sw $31,20($sp) sw $16,16($sp) move $16,$4 beq $4,$0,.L2 li $2,1 jal f addiu $4,$4,-1 mul $2,$2,$16 .L2: lw $31,20($sp) lw $16,16($sp) j $31 addiu $sp,$sp,24 ////////// c ////////// f: slt $3,$5,$4 bne $3,$0,.L5 nop addu $2,$2,$4 .L4: addiu $4,$4,1 slt $3,$5,$4 beq $3,$0,.L4 addu $2,$2,$4 subu $2,$2,$4 .L5: j $31 nop ////////// d ////////// f: nor $2,$0,$6 and $5,$2,$5 and $4,$4,$6 or $2,$5,$4 j $31 sw $2,%gp_rel(e)($28) ////////// e ////////// f: lui $3,%hi(a) addiu $3,$3,%lo(a) addiu $5,$3,40 .L3: lw $4,0($3) addiu $3,$3,4 bne $3,$5,.L3 addu $2,$2,$4 j $31 nop /////////////////////// Quiz is created by Yuri Panchul