Question

Write the corresponding MIPS I instruction to the C++ code segment below. for (; i <...

Write the corresponding MIPS I instruction to the C++ code segment below.

for (; i < 100; i ++) s = s + (2*i + 1);

  • Use the table below for variable-register association
Variable i s
Register $t0 $t1
  • Variables s has been initialized with 0; i has been initialized with 1. No need to write instruction for their initializations.
  • The instructions corresponding to the for-loop is labeled as "LOOP". The instructions following the for-loop is labeled by "DONE" (no need to implement DONE routine).
  • Start with writing a test instruction related to the condition. Choose a proper test instruction. Fill ONLY the necessary boxes. Fill NA in unnecessary boxes (if any).
  • Put space between label and mnemonic, space between mnemonic and operands, space between , and following symbol
  • Use beq instruction for branch. Do NOT re-write your borrowed temporary register.

1 # Use $t2 as the destination reg.

2   

3 # Use $t3 as the destination reg.

4 # Use $t4 as the destination reg.

5   

6

7

8

... DONE:

Homework Answers

Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

screen shot of code

code.asm

#i is in $t0
#s is in $t1

#initialize s to 0
li $t1,0
LOOP:

#check if i==100 jump to done
beq $t0,100,DONE

#get 2*i
mul $t2,$t0,2

#get 2*i+1
add $t2,$t2,1

#s = s +2*i+1
add $t1,$t1,$t2

#i++
add $t0,$t0,1

j LOOP
DONE:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
Can i get the answer to these questions in detail explaining how you go to the...
Can i get the answer to these questions in detail explaining how you go to the solution 1.Convert to/from Hex (0) 2.Octal Binary Unsigned/ 2’s complement 3.Understand how to shift and rotate. 4.Understand the relationship between shifting and multiplication/division 5.Be able to recognize and use the following gates: AND OR NOT NAND NOR XOR 6.Understand how a half adder works Given a logical statement ((A OR B) AND NOT(C OR A)) show the gates. 7.What is the difference between an...
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT