What would the code below end up doing Provide comments for

What would the code below end up doing? Provide comments for each line of code .data a: .word 3, 4, 5 .word 0 .text main: la $sb, a lw $s3, I lp: sll $t1, $s3, 2 add $t1, $t1, $sb sw $zero, 0($t1) add i $s3, $s3, 1 slt i $ta, $s3, 3 bne $ta, zero, lp

Solution

.data
a:       .word 3,4,5       ; word is assembler directive used to allocate and initialize space for a variable
       .word 0
      
       .text             ; read-only while data is not
main:                     ; start of code
      la   $sb, a         ; copy RAM address of \'a\' into register $sb initialize the a ( int a; )
      lw   $s3, i         ; load word at RAM address contained in i into $s3 s3 = i
      ;lp is loop started
lp:      sll $t1, $s3, 2    ; $t1 gets the bits in $s3 shifted left logical by 2 positions      while(a[i] == k){
      add $t1, $t1, $sb ; add content of $t1 and $sb and store result into $t1                   i = i+a
      sw   $zero, 0($t1) ; store word in register $zero into RAM at address contained in $t1+0    i = 0
                          ; $zero is a register that always equals zero  
      addi $s3, $s3, 1    ; add immediate content of $s3 and 1 ,result store into s3                i++
      slti $ta, $s3, 3    ; Set on l. t. immediate
      bne $ta, zero, lp ; branch jump to loop lp , if( i != 0 )                                  }   

 What would the code below end up doing? Provide comments for each line of code .data a: .word 3, 4, 5 .word 0 .text main: la $sb, a lw $s3, I lp: sll $t1, $s3,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site