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

Consider the following fragment of C code: if (A > B) C(A+B) elset C-(A+B) Consi

ID: 3913040 • Letter: C

Question

Consider the following fragment of C code: if (A > B) C(A+B) elset C-(A+B) Consider the following constraints to answer this question. ·Assume that A, B, and C are 64-bit integers. Use instructions for 64t irseg use DADD (for 64-bip instcad of ADD (or 32-6i0) All data values are kept in memory (at addresses 2000, 2008, and 2016 for A, B, and C, respec- tively). Assume that 4, 8, and 10 are stored in the memory addresses 2000, 2008, and 2016 respectively You must use BNE or BEQ instruction for the branching. (Hint: See SLT (Set-on-Less-Than) instruction. MIPS reference: http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html) In the next page, write your answers for the following questions: (a) Write the code in MIPS assembly (b) How many instructions are executed dynamically? (c) How many memory-data references will be executed? (d) What is the code size in bytes? (Count only the bytes for instructions.)

Explanation / Answer

a)

lui                    r1, 0x2000 ; load A

lui                    r2, 0x2008 ; load B

slt                    $r4, $r2, $r1                            ; if A > B

bne                  $r4 ,1, ELSE                           ; no then go to ELSE

dadd                $r1, $r1, $r2                            ; A+B

li                      $r2, 0x0

dsub                $r3, $r2, $r1                            ; -(A+B)

sw                    $r3, 0(0x2016) ; assign to C

b                      EXIT

ELSE:

dadd                $r1, $r1, $r2                            ; A+B

sw                    $r3, 0(0x2016) ; assign to C

EXIT:

_exit

b) 7 instructions are executed dynamically which does not include memory references.

c) 3 memory references, two for loading A & B and one for storing value of C(either if or else part).

d) 44 bytes, since each instruction takes 32 bits and there are 11 instructions.

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