Answer:
Step-by-step explanation:
Program
#Data declaration section
.data
numbers_len: .word 11
numbers: .word -27, 3, 46, -7, 11, 24, -5, 14, -18, 12, 35
index: .asciiz "Enter an integer: \\"
value: .asciiz "Enter another integer: \\"
Result: .asciiz "Result Array Content:\\"
nextline: .asciiz "\\"
#Main program
.text
#Index asking prompt
la $a0,index
li $v0,4
syscall
#Read index
li $v0,5
syscall
#store in s0
move $s0,$v0
#Prompt for div value
la $a0,value
li $v0,4
syscall
#Read value
li $v0,5
syscall
#Store in s1
move $s1,$v0
#Array length
lw $t1,numbers_len
#Loop to check the index and change the array
loop:
#Check index<0
blt $s0,0,printArray
#Check index>10
bgt $s0,10,changeArray
#Otherwise
#Loop to check division and change array elements
changeArray:
#Set t2=0 for counter
li $t0,2
#Address of the array
la $t0,numbers
changeIndexVal:
#Until index
bgt $t2,$s0,printArray
#Elements fro array
lw $t3,($t0)
#divide with value
div $t3,$s1
#store remainder in t4
mfhi $t4
#chech remainder
bne $t4,0,nextVal
#if remainder 0 then multiply
mul $t3,$t3,$s1
#store the new val in array
sw $t3,($t0)
#Increment counter
addi $t2,$t2,1
#increment address for next element
addi $t0,$t0,4
#continue
j changeIndexVal
#If remainder not 0
nextVal:
addi $t2,$t2,1
addi $t0,$t0,4
j changeIndexVal
#If index greater than 10
changeLoop:
#Loop until end of the array
beq $t2,$t1,printArray
#elements in t3
lw $t3,($t0)
#check remainder
div $t3,$s1
mfhi $t4
bne $t4,0,next
#if remainder 0 then change value of the array
mul $t3,$t3,$s1
sw $t3,($t0)
addi $t2,$t2,1
addi $t0,$t0,4
j changeLoop
#Otherwise
next:
addi $t2,$t2,1
addi $t0,$t0,4
j changeLoop
#Print array
printArray:
#Prompt the result
la $a0,Result
li $v0,4
syscall
li $t2,0
la $t0,numbers
#Loop for printing array elements
printLoop:
beq $t2,$t1,exit
lw $a0,($t0)
li $v0,1
syscall
la $a0,nextline
li $v0,4
syscall
addi $t2,$t2,1
addi $t0,$t0,4
j printLoop
#end of the program
exit:
li $v0,10
syscall
--------------------------------------
Output
Enter an integer:
5
Enter another integer:
3
Result Array Content:
-81
9
46
-7
11
72
-5
14
-18
12
35
-- program is finished running --