 # Answered! Consider the following fragment of ac program int [101, si int *pi for (p 131 p p++) Here is a buggy translation in…

there are 6 error in the answer one error accounts the entire line Don't use plagiarized sources. Get Your Custom Essay on
Answered! Consider the following fragment of ac program int [101, si int *pi for (p 131 p p++) Here is a buggy translation in…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Consider the following fragment of ac program int [101, si int *pi for (p 131 p p++) Here is a buggy translation in MIPS assembly language, assuming s is insi6 and p is in S19 or \$16, \$0, \$0 1 \$19, k 12 bne SB, finish add \$16, \$19, \$16 addi \$19, 1 j loop finish

C Code:

int k, s;

int *p;

s=10;

for(p=&k; *p!=0; p++)

s=s+p;

MIPS Code

or \$16,\$0,\$0

lw \$19,k+12

loop:

bne \$8, finish

j loop

finish:

or \$16,\$0,\$0

The syntax for the instruction ‘or’ is as follows

Or \$d,\$s,\$t

\$d=\$s|\$t

\$16=\$0|\$0

\$0 is a special purpose register so it contains value 0

\$16=0|0

\$16=0

It’s been told s is in \$16

s=0

lw \$19,k+12

The syntax for the instruction ‘lw’(load word) is as follows

lw \$t, offset(\$s)

\$t = MEM[\$s + offset]

The register \$t will contain the value present in the memory address given by offset +\$s

The given instruction lw \$19, k+12 is syntactically wrong.

bne \$8, finish

The syntax for the instruction ‘bne’(branch on not equal) is as follows

bne \$s,\$t, offset

if(\$s!=\$t) go to PC+4+offset

The given instruction bne \$8, finish is syntactically wrong.

\$d=\$s+\$t

\$16=\$19+\$16

s is in \$16 and p is in \$19

s=p+s

from the first line(or \$16,\$0,\$0) we know that s=0

0=p+0

0=p