Question

1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s
4. (40 pts) Consider the following MIPS loop: LOOP: slt $t2, Szero, $t1 beq $t2, $zero, DONE addi $t1, $t1, -1 addi $si, $81,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is as follows :

Answer 1 :

MIPS Code for given C statement :

lui $a1 , 5 // we don't subtract immediate value, so we temporary loads the data 5 to register $a1.

sub $s2, $s2 , $a1 // it will perform the (h-5) and store result back to h

add $s1, $s1 , $s2 // it will perform (g+h) where h is updated from last instruction and store result to g

sw $s1 , 0($s0) // calculated result in g stored to register $s0 i.e. consider as variable f

Answer 2 :

#include <stdio.h>

int main()
{
int f,g,h,i ; // intialize variables
int temp ; // temporary variable
f = g+h ; // perfrom "add f,g,h" instruction
f = i+f ; // perfrom "add f,i,f" instruction
  

return 0;
}

Answer 3 :

Part A :

opcode = 0 = 000000 (6 bits opcode)

rs = 18 = 10010 (source register 1, "5 bits") , equivalent to register $s2

rt = 9 = 01001 (source register 2, "5 bits") , equivalent to register $t1

rd = 20 = 10100 (destination register, 5 bits) , equivalent to register $s4

shamt = 0 = 00000 (5 bits shamt)

funct = 34 = 100010 (6 bit funct)

So the opcode is 0, the instruction is R-Type instruction

funct 100010 is used for SUB instruction, so instruction is SUB $s4 , $s2 , $t1

Binary Representation order is opcode -> source reg 1 -> source reg 2 -> destination reg ->shamt -> funct,

So binary representation is : 0000 0010 0100 1001 1010 0000 0010 0010

Part B :

opcode = 43 = 101011 (6 bit)

rs = 11 = 01011 (source register 1 , "5 bits") , equivalent to register $t3

rt = 18 = 10010 (source register 2, "5 bits") , equivalent to register $s2

address = 1000 (memory address 16 bits) , 0001 0000 0000 0000

So opcode is 43 or 101011 i.e. SW instruction used for storage. So it is I- Type instruction

MIPS SW instruction is : SW $s2 , 1000($t3)

Binary Representation order is opcode -> source reg 1 -> source reg 2 -> address

So binary representation is : 1010 1101 0111 0010 0001 0000 0000 0000

As HOMEWORKLIB Guidelines, we can only answer to four question including sub parts. So i answer four question i.e. Question 1, 2 and 3 (2 parts). So please repost the question 4. It would be helpful

if there is any query please ask in comments...

Add a comment
Know the answer?
Add Answer to:
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please explain fully 3. Consider the following MIPS loop: LOOP: Comment slt $t2, 0, Sti beg...

    please explain fully 3. Consider the following MIPS loop: LOOP: Comment slt $t2, 0, Sti beg $t2, 0, exit addi $t1, $t1,-1 addi Sal, $31, 2 TOOP exit: a. (5 pts) Write comments for each line, at the right side of above table. b. (12 pts) Write the equivalent C code. Assume that the registers $sland $t1 is associated with integers "a" and "I", respectively. c. (3pts) Assume that the register $t1 is initialized to the value 2. What is...

  • 2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2....

    2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...

  • For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables...

    For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C program. Use a minimal number of MIPS assembly instructions: f g(h 5); For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C...

  • Please answer the following questions involving MIPS assembly code: A) For the C statement below, what...

    Please answer the following questions involving MIPS assembly code: A) For the C statement below, what is the corresponding MIPS assembly code? Assume f, g are stored in S1 and S2. f = g + (-f -5) B) For the C statement below, what is the corresponding MIPS assembly code? Assume i and j are assigned in registers S1 and S2 respectively and base of address of arrays A and B are in registers S6 and S7. B[8] = A[i...

  • what is the corresponding MIPS assembly code for the statements shown below that written in C....

    what is the corresponding MIPS assembly code for the statements shown below that written in C. Assume that the variables sum and n assigned to register $t1 and $t2 respectively, and the base address of the array A is in register $t0. int sum = 0 for(n=100 ; n>=0; n=n-5) { if(A[n]>0 sum = a[n] +3 }

  • 4. (3 pts. each) Write the hexadecimal representation of each MIPS assembly instruction: (4.1) sub $s3,...

    4. (3 pts. each) Write the hexadecimal representation of each MIPS assembly instruction: (4.1) sub $s3, $t1, $s2 (4.2) bne $t3, $t4, 18 (4.3) sll $s0, $t5, 2 5. (20 pts.) Consider the following C (or java) code: else f=f+2; By storing the value of j in Ss0, write a sequence of MIPS assembly instructions that will execute these lines of code for the following two cases: (5.1) assuming that the values of f, g and h are stored in...

  • Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program:...

    Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program: loop: addi Sto, $to,-1 bne $to, $zero, loop Translate the second instruction into MIPS machine language and write it in hex. 2. (2 pt) Which best describes the reason that we maintain the stack pointer in a register? (circle one) i. The hardware forces use of a stack pointer. ii. We need a local pointer because we are often limited to relative addressing. ili....

  • 3. For the following C statement what is the corresponding MIPS assembly code? A[24] = h...

    3. For the following C statement what is the corresponding MIPS assembly code? A[24] = h + A[16]; Assume variable h to $51, base address of A in $s2. 4. Suppose $t1 initially contains Ox3A67AB25. C. After following code runs on big-endian system, what value is $50? d. In a little-endian system? sw $t1, 0($0) Ib $50, 1($0)

  • For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold...

    For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold 16-bit integer values, $ s0 is the base for array X, $ s1 is the base for array Y, and $ t0 and $ t1 are index variables i and j respectively. Comment code X [j] = Y [i + j];

  • Consider the following MIPS assembly language instructions: addi $1, $2, 100 swr $1, 0($2): addi $rt,...

    Consider the following MIPS assembly language instructions: addi $1, $2, 100 swr $1, 0($2): addi $rt, $rs, immediate # add immediate swr $rt, immedi ate ($rs) # store word write register These instructions are I-format instructions similar to the load word and store word instructions. The addi and swr instructions store a computed value to the destina- tion register $rt. The instructions do not require any physical hardware changes to the datapath. The effect of each instruction is given below....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT