Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

.

data
a: .word 7
b: .word 0, 0, 0
space: .asciiz " " # Define a space character

.text
.globl main
main:
la t0, a
lw s1, 0(t0) # Load value of a into s1
la s2, b
addi s0, x0, 0 # s0 holds i
addi t1, x0, 3 # t1 = 3

loop:
bge s0, t1, exit # Check if i >= 3, exit loop

mul t2, s0, s1 # Calculate a + (i * a)


add t2, s1, t2

slli t3, s0, 2 # Calculate i * 4 (each int takes 4 bytes)


add t4, s2, t3 # Calculate address of b[i]

# Print b[i] after calculation


addi a0, x0, 1 # Print integer
add a1, t2, x0 # Load value to print
ecall # Print value of b[i]

# Print a space after each value


addi a0, x0, 4 # Print string
la a1, space # Load space character
ecall # Print space

# Store value in b[i]


sw t2, 0(t4) # Store calculated value in b[i]

addi s0, s0, 1 # i++


j loop # Jump back to loop

exit:
ret # Return from the loop

You might also like