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
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction...
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction and write the decimal values of each instruction field. addi $v0, $zero, 0 loop: lw $v1, 0($a0) sw $v1, 0($a1) sll $a0, $a0, 2 add $a1, $a1, $a0 beq $v1, $zero, loop 1b. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C language code and indicate the content of each register with the corresponding variable in C-code. muli $t2, $s1, 4    add $t2, $t4, $t2    lw $t15, 0($t2)    lw $t16, 4($t2)    sw $t16, 0($t2)    sw $t15, 4($t2)
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, and I are assigned to registers $s0 - $s3, respectively. Assume that the base address of arrays X, Y, and Z are in registers $s4 - $s6, respectively. Be conservative and use a single temp register as possible. It is a C arithmetic command with two source operands and a destination. Each part is 3 points. Add $t0, $s0, $s1 addi...
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 ;...