. In the C, the following idouble following linked list node is sred truct node
ID: 3723492 • Letter: #
Question
. In the C, the following idouble following linked list node is sred truct node double val; struct node ext link St4, 8(St1) St4, 8(St3) ti ane pointers are declared by "st n te lst. 3 is an and t2 point to to node. Asume that all links a and that sw to two successive have and point to valid addresse ha Write the utraryl pointers tl, 12, and 13, respextively MIPS registers Sti, S2, and s3 sw S13, S(St1) codes above in one equivalent operation of the or two C statements. ts uivalent operation of the MIPS codes abovein 7. Fill in mission through smients x anesions in C code, coeening to ts assembly code oa the are passed via SaO and Sal, respectively, and the return o argunexpressions in C sode commscnding to its assembly code on the right, where values is int testlint x, int y) bge ble mul $ao, -3, L2 SaO, Sal,L3 Sao, Sao, Sa1 L4 int val = if Di L3: add $ao, $a0, $a1 if L val else val b L bgt xor SaO, 2, $LS $a0, $a0, Sa1 L2: L4 Sub 4 L4: r $ra L5: sub $ao, Sa0, Sa1 else if val=- return val;Explanation / Answer
6. The struct 'node' is holding the data of type 'double'. Therefore to access the next pointer(next node), it has to add the size of double(8 bytes) to the current node. Therefore the equivalent C code for first two lines of assembly code is:
t3->next=t1->next; or
t3->next=t2 ;
Because t1->next =t2, as t1 and t2 are successive nodes in the list.
Is equivalent to
lw $t4,8($t1)
sw $t4,8($t3)
Here 8($t1) is equivalent to t1->next or t2 and 8($t3) is equivalent to t3->next as I mentioned above.
Equivalent C code of last line in assembly code is:
t1->next=t3;
sw $t3,8($t1)
Two instructions in C are
t3->next=t1->next;
t1->next=t3;
or
t3->next=t2;
t1->next=t3;
7. Equivalent C code:
For Assembly instruction that is a conditional instruction(branch), the instruction at the target address is the instruction to be executed if the branch condition is true. If it is false, then the instruction following the branch instruction is the instruction to be executed in else part. In this way the instructions are translated to its equivalent C instructions.
int test(int x, int y){
int val = x*y; //mult $a0,$a0,$a1 -> instruction following the "ble" instruction for which else part is not given
//in C program. Hence placing this calculation here.
if (x > -3){ // bge $a0,-3,L2
if (x > 2) // bge $a0,2,L5
val = x-y; // sub $a0,$a0,$a1
else
val= x ^ y; // xor $a0,$a0,$a1
}
else if(x < y) //ble $a0,$a1,L3
val= x +y; // add $a0,$a0,$a1
return val;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.