Comment each line of the following MIPS assembly language, and briefly describe
ID: 3839040 • Letter: C
Question
Comment each line of the following MIPS assembly language, and briefly describe the task it performs.
(Hints: $v0 is a counter, what is in $v1?)
addi $v0, $zero, -1 #_______________________________________
loop:
lw $v1, 0($a0) # mem($a0 + 0) +> $v1, read next word from source
sw $v1, 0($a1) #__________________________________________
addi $v0, $v0, 1 #___________________________________________
addi $a0, $a0, 4 # ___________________________________________
addi $a1, $a1, 4 #___________________________________________
bne $v1, $zero, loop #_______________________________________
Description of the function of above piece of code:
Explanation / Answer
addi $v0, $zero, -1 # Basic Initialisation so that we dont count zero word
loop:
lw $v1, 0($a0) # mem($a0 + 0) +> $v1, read next word from source
sw $v1, 0($a1) #we write the contents of v1 to the address pointed on a1 i.e It does a Store Word
addi $v0, $v0, 1 # It Increments the count words which is copied by 1
addi $a0, $a0, 4 # By incremeting the a0 by 4 , we Advance pointer to next location and its the source
addi $a1, $a1, 4 # This helps us Advance pointer to next destination
bne $v1, $zero, loop # This is a branch Instruction, We Loop if word copied != zero