Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. (50 points) The following C statements updates an element of Array num. int n

ID: 3757252 • 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[4] + ai else num[4] - a + b, Let us assume registers t1 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

3)

a )If else corresponding assembly

.text

#If check

beq $t2,$t3,if

#Else implementation
add $t4,$t2,$t3
sw $t4,16($t1)
#If loop implementation
if:
lw $t4,16($t1)
add $t4,$t4,$t2
sw $t4,16($t1)
----------------------------------

b)Addressing modes ,datapath and control signals

Addressing modes:-

.text

#If check

beq $t2,$t3,if           --> I-Type

#Else implementation
add $t4,$t2,$t3      --->R-type
sw $t4,16($t1)      --> I-Type
#If loop implementation
if:
lw $t4,16($t1)        -->I-Type
add $t4,$t4,$t2    --->R-type
sw $t4,16($t1)     ---> I-Type

Datapath

*) add $t4,$t4,$t2:-

*)lw $t4,16($t1)

*)sw $t4,16($t1)

*)beq $t2,$t3,if:-

ControlSignals

Instruction RegDst RegWrite MemRead MemWrite MemToReg Branch ALU Src ALU op1 ALU op2 Add 1 1 0 0 0 0 0 1 0 LW 0 1 1 0 1 0 1 0 0 SW x 0 0 1 x 0 1 0 0 Beq x 0 0 0 x 1 0 0 1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote