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

2. a. Write MIPS code to perform addition of two unsigned numbers in registers S

ID: 3724697 • Letter: 2

Question

2. a. Write MIPS code to perform addition of two unsigned numbers in registers St1 and St2 and then verify whether the result has overflowed the 32-bit long destination register S13. Explain the overflow logic with comments to elaborate upon each linc of MIPs code. Explaining what each MIPS instruction does literally is not enough, yow need to explain how it contributes to (4 Marks) the overal logic hardware. may be performed b. Indicate how a very simplified implementation of the same overflow logic is possible in (I Mark) c. Explain with a flow chart and architecture diagram hardware efficient division algorithm 4 Marks) d. Explain why massively parallel implementation of the division algorithum not possibie (½ Mark)

Explanation / Answer

MIPS CODE (A)

#---------------------------------------------------------------------------------------#

        .data

A:          .word       # Store the number 4 as an integer in var1 # $t1 is used

B:          .word       # Store the number 2 as an integer in var2 # $t2 is used

S:          .word       # Store the sum of A and B          # $t3 is used

Prompt1:    .asciiz "Please enter first number: "

Prompt2:    .asciiz "Please enter second number: "

Result:     .asciiz "The sum of A and B is: "

        .text

main:

    #--------------------------------------------------------#

    #Display first prompt

    li $v0, 4      # Load instruction "print string"

    la $a0, Prompt1    # Load prompt into $a0

    syscall

    #Read first integer

    li $v0, 5      # Read 1st integer

    la $t1, A      # $t1 = A

    syscall

    #Store first integer into memory

    move    $t1, $v0    # Move contents in $v0 to $t1

    sw $t1, A      # A = value at $t1

    #--------------------------------------------------------#

    #Display second prompt

    li $v0, 4      # Load instruction "print string"

    la $a0, Prompt2    # Load prompt into $a0

    syscall

    #Read second integer

    li $v0, 5      # Read 1st integer

    la $t2, B      # $t1 = A

    syscall

    #Store second integer into memory

    move    $t2, $v0    # Move contents in $v0 to $t2

    sw $t2, B      # A = value at $t1

    #--------------------------------------------------------#

    #Add the two variables

    la $t3, S      # $t3 = S

    add     $t3, $t1, $t2 # $t3 = $t1 + $t2

    sw $t3, S      # S = value at $t3

    #Display the Result prompt

    la $a0, Result # Loads Output label to be printed

    li $v0, 4      # Sysycall to print string

    syscall

    #Display the sum

   lw $a0, S      # $a0 = value at S

    li $v0, 1      # Syscall to print integer

    syscall

#Exit the program

Here unsigned numbers are there so overflow will not take place in $t3 register.

C)

while N D do

N := N D

end

return N

function divide(N, D)

if D = 0 then error(DivisionByZero) end

if D < 0 then (Q, R) := divide(N, D); return (Q, R) end

if N < 0 then

    (Q,R) := divide(N, D)

    if R = 0 then return (Q, 0)

    else return (Q 1, D R) end

end

-- At this point, N 0 and D > 0

Q := 0; R := N

while R D do

    Q := Q + 1

    R := R D

end

return (Q, R)

end

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