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

28. Consider the following QtSPIM screen shot. [00400038] 0085082a slt $1, $4, $

ID: 3907634 • Letter: 2

Question

28. Consider the following QtSPIM screen shot.

[00400038] 0085082a  slt $1, $4, $5           ; 13: bge $a0, $a1, ELSE
[0040003c] 10200002  beq $1, $0, 8 [ELSE-0x0040003c]

The MIPS machine codes of the slt (0085082a) and beq (10200002) instructions are shown in HEX format. Which of the following is true? [hint: op-code is first 6 bits and fn-code is last 6 bits]

a. SLT is R-type, because the first byte is 0x00 = 000000002; therefore, the op-code is 000000

b. The fn-code of SLT is 101010 = 42, because the last byte is 0x2a = 001010102

c. The op-code of beq is 000100 = 4, because the first byte is 0x10 = 000100002

d. All of the above are true

29. What is the RTL description of the instruction JAL sub? [note that, the order is important. &sub stands for the address of the label sub]

        addi $t0, $0, 5
        addi $a0, $t0, $0
         jal TEST
        move $t0, $v0
        j END
TEST:
         add $v0, $a0, $a0
         jr ra
END:       


a. R[ra] ß PC + 4 , PC ß &sub

b. PC ß &sub, R[ra] ß PC + 4

c. R[ra] = &sub, PC ß PC + 4

d. R [ra] ß PC , PC ß &sub

30. Consider the following MIPS program. After execution, what will be the value in $t0 when PC points the label END?

a. 5

b. 10

c. 0

d. Cannot be determined

31. Consider the following java code. Write equivalent MIPS assembly code. Assume that the compiler keep values of the variables A and B in the registers $t0 and $t1 respectively.

if ( A > B)
     A = A – B;
else
      B = B - A


[00400038] 0085082a  slt $1, $4, $5           ; 13: bge $a0, $a1, ELSE
[0040003c] 10200002  beq $1, $0, 8 [ELSE-0x0040003c]

Explanation / Answer

Answer 28: d. All of the above are true

Explanation:

a. SLT is R-type because first 6 bit (op-code) are all zeroes, hence op-code is 000000.

b. fn-code is last 6 bits. Last byte is 0x2a (00101010) = 101010 is fn-code of SLT.

c. op-code is first 6-bits. First byte is 0x10 (00010000) = 000100 is op-code of beq.

d. Thus all of the above are true.

Answer 29: a. R[ra] ß PC + 4 , PC ß &sub

Explanation:

JAL instruction store the return address of next instruction in ra register for return. The address of sub is stored to PC.

Answer 30: b. 10

Explanation:

addi $t0, $0, 5   (It means $t0 = 5)
        addi $a0, $t0, $0  (It means $a0 = 5)
         jal TEST (Pointer moves to TEST label and calculate the value of $v0)
        move $t0, $v0  (It means $t0 = $v0 = 10)
        j END
TEST:
         add $v0, $a0, $a0  (It means $v0 = $a0 + $a0 = 5 + 5 = 10 and pointer return to the jal instruction)
         jr ra
END:

Thus the value of $t0 is 10.

Answer 31:

slt $t2, $t1, $t0 # if ($t1 < $t0) then $t2 = 1

beq $t2, $zero, ELSE

sub $t0, $t0, $t1 # A = A - B

j END # jump to end

ELSE:

sub $t1, $t1, $t0 #B = B - A

END:

Please give thumbsup if you like it. Thanks.

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