.data A: .word 2, 3, 4, 5 # Example elements for array A n1: .word 4 # Length of array A B: .space 16 # Allocate space for array B (4 elements * 4 bytes each) .text .globl main main: # Load base addresses and length of A la $a0, A # Address of A into $a0 la $a1, B # Address of B into $a1 lw $t0, n1 # Length of A into $t0 (n1) li $t1, 0 # Initialize n2 (current length of B) # Initialize B[0] = 1 (A[0]^0 = 1) sw $zero, 0($a1) # Store 0 (which is 1^0) at B[0] li $t2, 1 # Start loop from j=1 loop: bge $t2, $t0, end_loop # Exit loop if j >= n1 # Prepare arguments for exponent lw $a2, 0($a0) # Load A[j] into $a2 move $a3, $t2 # Index j into $a3 # Call exponent jal exponent # Get result from exponent move $a3, $v0 # Result from exponent to $a3 (new element) # Call append jal append addiu $t1, $t1, 1 # Increment n2 addiu $t2, $t2, 1 # Increment loop index addiu $a0, $a0, 4 # Move to next element in A j loop end_loop: jr $ra # Return from main # Function: exponent # Calculates x^y, result in $v0 exponent: move $t3, $a2 # $t3 = x li $v0, 1 # $v0 = result (start as 1) beq $a3, $zero, ret_exp # If y == 0, return 1 exp_loop: mul $v0, $v0, $t3 # result *= x addi $a3, $a3, -1 # Decrement y bgtz $a3, exp_loop # Continue if y > 0 ret_exp: jr $ra # Return from exponent # Function: append # Appends exp to B at index n2 append: mul $t4, $t1, 4 # Calculate offset for B (n2 * 4) add $t5, $a1, $t4 # Address to store new element sw $a3, 0($t5) # Store new element at B[n2] jr $ra # Return from append