Question

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

$t0, $t0, -1

sll

$t0, $t0, 2

add

$t0, $s4, $t0

lw

$t0, 0($t0)

sub

$t1, $s2, $s3

addi

$t1, $t1, -1

sll

$t1, $t1, 2

add

$t1, $s5, $t1

lw

$t1, 0($t1)

add

$t0, $t0, $t1

add

$t1, $s1, $s2

sll

$t1, $t1, 2

add

$t1, $t1, $s6

sw

$t0, 0($t1)

Homework Answers

Answer #1

f: $s0
g: $s1
h: $s2
i: $s3
X: $s4
Y: $s5
Z: $s6
Lets assume temp = $t0
           temp1 = $t1

ADD $t0, $s0, $s1   # Add $s0, $s1, and store in $t0: temp = f+g
ADDI $t0, $t0, -1 # Decrement $t0: $t0 = $t0 - 1, or temp--
SLL $t0, $t0, 2   # Shift Left $t0 by 2 bits: temp = temp << 2
ADD $t0, $s4, $t0   # Add $s4, $t0, and store in $t0: temp = temp + X[0], or temp += X[0]
LW $t0, 0($t0)   # Load from $t0 to $t0: temp = temp (This doesn't make much sense.)
SUB $t1, $s2, $s3 # Subtract $s3 from $s2, and store in $t1: temp1 = h - i
ADDI $t1, $t1, -1   # Decrement $t1: $t1 = $t1 - 1, or temp1--
SLL $t1, $t1, 2       # Shift Left $t1 by 2 bits: temp1 = temp1 << 2
ADD $t1, $s5, $t1   # Add $s5, $t1, and store in $t1: temp1 = temp1 + Y[0], or temp1 += Y[0]
LW $t1, 0($t1)       # Load from $t1 to $t1: temp1 = temp1 (This doesn't make much sense.)
ADD $t0, $t0, $t1   # Add $t0, $t1, and store in $t0: temp = temp + temp1, or temp += temp1
ADD $t1, $s1, $s2   # Add $s1, $s2, and store in $t1: temp1 = g + h
SLL $t1, $t1, 2       # Shift Left $t1 by 2 bits: temp1 = temp1 << 2
ADD $t1, $t1, $s6   # Add $t1, $s6, and store in $t1: temp1 = temp1 + Z[0], or temp1 += Z[0]
SW   $t0, 0($t1)       # Store Word $t1 into $t0: temp = temp1

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
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0,...
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0, 64($S1) add $t0,$S0,$S1 sub $t1,$S3,$S4 sw $t1,100($S1) addi $S4,$S6,100
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...
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...
Suppose a MIPS processor uses the simple 5-stage pipeline described in the text, where the stages...
Suppose a MIPS processor uses the simple 5-stage pipeline described in the text, where the stages are instruction fetch, instruction decode and operand fetch, execute and calculate address, memory access, and register write. Suppose further that • There is a single memory for both instruction and data, which can only support one read or write each cycle. • There is no “forwarding” in the pipeline. Thus, if an instruction B relies on a value written into a register by an...
Consider the following C statement:           a = (b + d) + (b – c) +...
Consider the following C statement:           a = (b + d) + (b – c) + (c + d) Which of the following assembly instructions can be used to replicate all or part of this statement in MIPS, without changing or reducing the equation. Assume variables a, b, c, and d are assigned to registers $s0, $s1, $s2 and $s3 respectively. sub $t0, $s2, $s3 sub $t0, $s0, $s3 sub $t1, $s1, $s2 add $t2, $s1, $s3 add $t2, $s0,...
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)
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3,...
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits). A[21] = B[0] + C[16];
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What...
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What is the negation of EDCC in HEX? 3) Convert it to decimal number if this is a 2s-complement signed binary representation in 16- bit register 4) Convert it to decimal number if this is an unsigned binary representation in 16-bit 2. Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s...
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...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT