3. (50 points) The following C statements updates an element of Array num. int n
ID: 3757066 • Letter: 3
Question
3. (50 points) The following C statements updates an element of Array num. int num[10], a-2, b-3; if (a - b) num[4] - num[41 a; else num[4]- a + b; Let us assume registers t holds the beginning address of Array num. In addition, t2 and t3 hold the value of a and b, respectively a. (20 points) Convert the if-else statement in C to assembly instructions. b. (30 points) For each assembly instruction you have provided for Question (a), describe the memory addressing mode used in that instruction, as well as all datapath elements and control signals that are necessary to support that instruction. Use diagrams when necessary.Explanation / Answer
Solution :
a)
Here t1 holds the beginning address of array num.
to compare elements stroed in t2 and t3 use CMP as given blow :
CMP $t2, $t3
BEQ equal
add $t4, $t2, $t3
sw $t4, 4($t1)
equal :
lw $t4, 4($t1)
add $t4, $t4, $t2
sw $t4, 4($t1)
here given code is the MIPS code for C code in question.
b)
Addressing mode of each instruction is given below :
CMP $t2, $t3 // register mode
BEQ equal // immediate addressing mode
add $t4, $t2, $t3 // register mode
sw $t4, 4($t1) // Base addressing or index mode.
equal :
lw $t4, 4($t1) // Base addressing
add $t4, $t4, $t2 // register mode
sw $t4, 4($t1) // Base addressing
if you have any doubts then you can ask in comment section if you find the solution helpful then upvote the answer. Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.