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

Write a MIPS program with comments that swaps the contents of the two consecutiv

ID: 3629484 • Letter: W

Question

Write a MIPS program with comments that swaps the contents of the two consecutive memory locations with the two other consecutive locations.
Example :

(2000) : 45 (3000) : 78
(2004) : 67 (3004) : 90

before execution

(2000) : 78 (3000) : 45
(2004) : 90 (3004) : 67

after execution

Use labels in your program instead of absolute addresses as below :

first_loc .word 45,67
sec_loc .word 78,90

To load the addresses to registers, use the pseudo instruction la (load address) as below :

la $s0, first_loc # address first_loc is loaded to register s0

Explanation / Answer

please rate - thanks

.data
first_loc: .word 45,67
sec_loc: .word 78,90
.text
.globl main
main:
la $s0, first_loc      # address first_loc is loaded to register s0
la $s1, sec_loc      # address first_loc is loaded to register s1
lw $s2,0($s0)       #get first_loc
lw $s3,0($s1)         #get sec loc
sw $s2,0($s1)       #store first in second
sw $s3,0($s0)       #store second in first
addi $s0,$s0,4       #go to loc next to first
addi $s1,$s1,4       #go to location next to second
lw $s2,0($s0)        #and repeat
lw $s3,0($s1)
sw $s2,0($s1)  
sw $s3,0($s0)

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