Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Translate the following MIPS code to C. Assume that the variables f, g, h, i, and j are assigned to registers \(s0, \)s1, \(s2, \)s3, and \(s4, respectively. Assume that the base address of the arrays A and B are in registers \)s6 and \(s7, respectively.

addi \)t0, \(s6, 4

add \)t1, \(s6, \)0

sw \(t1, 0(\)t0)

lw \(t0, 0(\)t0)

add \(s0, \)t1, $t0

Short Answer

Expert verified

The C code:

A [1] = A[0];

f = & A[0] + A[1];

Step by step solution

01

Define MIPS assembly code

MIPS stands for Microprocessor without interlocked pipeline. To write MIPS assembly code we should know about Registers and instructions format each MIPS instruction is of 32 bits

02

Convert addi  $t0,   $s6,  4 MIPS code to C

addi $t0,$s6,4

$t0=$s6+4$t0=&A[1]

03

Convert add  $t1, $s6, $0 MIPS code to C

add$t1,$s6,$0$t1=$s6+$0$t1=$s6$t1=&A[0]

04

Convert sw $t1, 0($t0) MIPS code to C

sw$t1,0($t0)Memory[$t0+0]=$t1Memory[&A0]=$t1

A[0] will have the address of A[1]

05

Convert lw $t0, 0($t0) MIPS code to C

lw$t0,0($t0)$t0=Memory[$t0+0]$=Memory[$t0]=Memory[&A[1]]

06

Convert add  $s0, $t1, $t0 MIPS code to C

add$s0,$t1,$t0

$s0=$t1+$t0=&A[0]+A[1]f=&A[0]+A[1]

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free