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

I need help with MIPS Assembly Language. I\'m using the MARS program development

ID: 3792844 • Letter: I

Question

I need help with MIPS Assembly Language. I'm using the MARS program development environment.

The program should begin by loading the contents of four signed integer operands (A, B, C, and D) from memory into registers. Next, your program should use the shift and rotate instructions to multiply the value of A by 5, divide the value of B by 4 (truncating the result), shift the value of C to the right 3 bit places (writing 0s into the most significant bits of the register), and rotate the value of D 2 bit places to the left. Finally, the program should write the new values of A, B, C, and D back to memory. Be sure to test the program carefully, using both positive and negative integers for inputs. Validate correct program operation by examining the updated contents of the memory operands. Do NOT use multiply or divide instructions! (HINT: 5A = 4A + A.) Be careful to select the best shift instruction for each task.

Explanation / Answer

.text

main: #tell linker entry point

   addi $s0,$zero,0
   addi $s1,$s0,0       #address of a
   addi $s2,$s0,4       #address of b
   addi $s3,$s0,8       #address of c
   addi $s4,$s0,12       #address of d
  
   #load in to register from memory
   lw $t0,A
   lw $t1,B
   lw $t2,C
   lw $t3,D
  
   sll $t0,$s1,2       #multiply by 4 so A = 4A
   add $t0,$t0,$s0       #add A in previous value of A so finally A = 4A + A = 5A
   li $v0, 1     # service 1 (print integer)
   move $a0,$t0
   syscall     # issue service
  
  
   srl $t1,$s2,2       #right shift by 2 so B = B/4  
   li $v0, 1 # service 1 (print integer)
   move $a0,$t1
   syscall # issue service
  
   srl $t2,$s3,3       #right shift by 3
   li $v0, 1 # service 1 (print integer)
   move $a0,$t2
   syscall # issue service
  
   sll $t3,$s4,2   #left shift D by 2
   li $v0, 1 # service 1 (print integer)
   move $a0,$t3
   syscall # issue service
  
   la $t5,array
  
   #store back to memory from register
   sw $t0,($t5)
   sw $t1,4($t5)
   sw $t2,8($t5)
   sw $t3,12($t5)
  
.data

A:   .word    4
B:   .word   4
C:   .word   4
D:   .word   4
array:   .space   16

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