addi $9, $zero, 0 addi $12, $zero, 5000 Loop: addi $12, $12, 4 lw $8, 40($12) ad
ID: 3620613 • Letter: A
Question
addi $9, $zero, 0addi $12, $zero, 5000
Loop: addi $12, $12, 4
lw $8, 40($12)
add $9, $9, $8
addi $11, $11, -1
bne $11, $zero, Loop
For the above MIPS program, determine the instruction format for the lw and bne instructions and the values of each instruction field. You may want to refer to the MIPS reference card available here: http://refcards.com/docs/waetzigj/mips/mipsref.pdf.
Also provide the binary and hex values for the complete instruction.
For example, for the instruction
lw $v1,0($a0),
the instruction format is I;
the instruction fields are op=2316 = 3510, rs=410, rt=310, imm=010;
the binary value of the instruction is therefore
100011 00100 00011 0000000000000000,
and the hex value is
0x8C830000
Explanation / Answer
I-type instruction format for lw:
Opcode(6)
rs(5)
rt(5)
Immediate(16)
lw rt, immediate (rs)
lw $8, 40($12)
I-type instruction format for bne:
Opcode(6)
rs(6)
rt(5)
16-bit address
bne rs, rt, Label next instruction is at Label if rs !=rt
bne $11, $zero, Loop
Opcode(6)
rs(5)
rt(5)
Immediate(16)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.