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

3) 1,2,3, and 4 returned in Svo eturned in Sfo turned in Sfo Spring 2018 and Org

ID: 3734559 • Letter: 3

Question

3) 1,2,3, and 4

returned in Svo eturned in Sfo turned in Sfo Spring 2018 and Organization 3. ( 1 8%) The following MIPS Assembly program contains a loop construct label next). Please answer the following questions: 1) What are the values ofregisters Sao and Sto just before running the loop? (from label loop to data initA: word 20 -30 40-50 10 unitX: word ? (2) What are the values of registers Sa0, Sto0, and Stl after the first iteration of the loop? text globl mairn main: li Sa0, 0 li St0, 20 loop: blez St0, done (3) What are the values of registers $a0, St0, and Stl after the second iteration of the loop? addi lw bltz add Sto, St0,-4 Stl, initA(St0) St1, next Sa0, Sa0, Stl next: b loop done: sw Sa0, unitX($0) (4) What are the values of registers Sa0, $t0, and Stl after the loop is done? li SvO, 10 syscall (5) How many iterations of the loop? What is the value at memory location unitX after the program finishes? 4 (6%) Translate the following arithmetic expression into MIPS assembly instructions. 5. (600) Given the following the data definition, please write a segment of MISP code usin SPIM system call to display the string "Hello Worldn" data .asciiz "Hello Worldm" str: #define a character string

Explanation / Answer

3.

initA : .word 20 -30 40 -50 10

unitX: .word ?

         .text

         .globl main

main:   li   $a0 , 0                    ; Load 0 into $a0

           li $t0    , 20                   ; Load 20 into $t0

loop:    blez     $t0 , done          ;Branch to done if $t0<=0

           addi     $t0, $t0, -4         ; $t0 = $t0 - 4

          lw        $t1 , initA($t0)      ; Load $t1 with value stored at initA($t0)

          bltz      $t1,   next            ; if $t1<0 then branch to next

         add       $a0, $a0,$t1         ; $a0 = $a0 +$t1

next:   b     loop                         ; branch to loop

done:    sw    $a0, unitX($0)        ; Store $a0 to unitX($0)

          li   $v0 , 10                     ;code for syscall

          syscall

(a) Just before the loop , $a0 = 0 and $t0 = 20

(b) First iteration of loop

           blez     $t0 , done          ;$t0 is greater than 0 therefore move to next instruction

           addi     $t0, $t0, -4         ; $t0 = 20 - 4 = 16

          lw        $t1 , initA($t0)      ; $t1 = 10

          bltz      $t1,   next            ; $t1>0 therefore move to next instruction

         add       $a0, $a0,$t1         ; $a0 = 0 + 10 = 10

So, at the end of first iteration of loop , $a0 =10

$t0 = 16

$t1 = 10

(c) During 2nd iteration

          blez     $t0 , done          ;$t0=16 which is greater than 0 therefore move to next instruction

           addi     $t0, $t0, -4         ; $t0 = 16 - 4 = 12

          lw        $t1 , initA($t0)      ; $t1 = -50

          bltz      $t1,   next            ; $t1<0 therefore jump to next label

         add       $a0, $a0,$t1         ; this will not be executed

So, at the end of 2nd iteration of loop , $a0 =10

$t0 = 12

$t1 = -50

(d) In 3rd iteration

blez     $t0 , done          ;$t0=12 which is greater than 0 therefore move to next instruction

           addi     $t0, $t0, -4         ; $t0 = 12 - 4 = 8

          lw        $t1 , initA($t0)      ; $t1 = 40

          bltz      $t1,   next            ; $t1>0 therefore move to next instruction

         add       $a0, $a0,$t1         ; $a0 = 10+40 =50

So, at the end of 2nd iteration of loop , $a0 =50

$t0 = 8

$t1 = 40

In 4th iteration

blez     $t0 , done          ;$t0=12 which is greater than 0 therefore move to next instruction

           addi     $t0, $t0, -4         ; $t0 = 8 - 4 = 4

          lw        $t1 , initA($t0)      ; $t1 = -30

          bltz      $t1,   next            ; $t1<0 therefore jump to next label

         add       $a0, $a0,$t1         ; this will not be executed

So, at the end of 2nd iteration of loop , $a0 =50

$t0 = 4

$t1 = -30

In 5th iteration

blez     $t0 , done          ;$t0=8 which is greater than 0 therefore move to next instruction

           addi     $t0, $t0, -4         ; $t0 = 4 - 4 = 0

          lw        $t1 , initA($t0)      ; $t1 = 20

          bltz      $t1,   next            ; $t1>0 therefore move to next instruction

         add       $a0, $a0,$t1         ; $a0 = 50+ 20 = 70

So, at the end of 2nd iteration of loop , $a0 =70

$t0 = 0

$t1 = 20

Once $t0 becomes 0 code jumps to done.

Values of registers once loop is done:

$a0 = 70

$t0 = 0

$t1 = 20

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