Please help need help to display reverse array in assembly, I attached the goal output my code so far: .data myarray: void 0,0,0,0,0,0,0,0,0,0 str1: .asciiz "Program Description: A program that reverses values in an array\n" str2: .asciiz "Author: Student \n" str3: .asciiz "Date: 02/16/23\n" str4: .asciiz "Enter a number between 1-10 for the array" str5: .asciiz "Enter" str6: .asciiz " number\t" str7: .asciiz " raised to the power of " error1message: .asciiz "Array limit cannot exceed 10, try again:\n" error2message: .asciiz "Array is not between 1-12, Try Again:\n" output: .asciiz "Product of numbers is: " newline: .asciiz "\n" .text li $v0, 4 la $a0, str1 syscall li $v0, 4 la $a0, str2 syscall li $v0, 4 la $a0, str3 syscall li $s3, 0 li $s4, 12 la $s1, myarray li $s0, la arraylimit: li $v0, 4 la $a0, str4 syscall li $v0, 4 la $a0, newline syscall li $v0, 5 syscall add $s1, $v0, $0 #storing into $s1 the array limit value ble $s1, $s3, error1 bge $s1, $s4, error1 arrayvalue: li $v0, 4 la $a0, str5 # "Enter " syscall li $v0, 4 la $a0, str6 #"number" syscall li $v0, 5 syscall add $s2, $v0, $0 #storing into $s2 thearray value ble $s2, $s3, error2 bge $s2, $s4, error2 li $s5, 0 addi $s6, $0, 1 inloop: li $v0, 4 la $a0, newline syscall beq, $s0, $0, next li $v0, 5 syscall sw, $v0 addi $s1, $s1, 4 addi $s0, $s1, -1 li $v0, 4 la $a0, newline syscall j inloop error1: li $v0, 4 la $a0, newline syscall li $v0, 4 la $a0, error1message syscall j arraylimit error2: li $v0, 4 la $a0, newline syscall li $v0, 4 la $a0, error2message syscall j arrayvalue exit: add $a0, $s1, $0 li $v0, 1 syscall li $v0, 4 la $a0, str7 syscall add $a0, $s2, $0 li $v0, 1 syscall li $v0, 4 la $a0, output syscall add $a0, $s6, $0 li $v0, 1 syscall li $v0, 10 syscall next: li, $s0, 10 #update loop counter la, $s0, myarray outloop:beq $s0, $0, done la $a0, 0($s1) li $v0, 1 syscall addi $s1, $s1, 4 addi $s0, $s0, -1 j outloop
Please help need help to display reverse array in assembly,
I attached the goal output
my code so far:
.data
myarray: void 0,0,0,0,0,0,0,0,0,0
str1: .asciiz "Program Description: A program that reverses values in an array\n"
str2: .asciiz "Author: Student \n"
str3: .asciiz "Date: 02/16/23\n"
str4: .asciiz "Enter a number between 1-10 for the array"
str5: .asciiz "Enter"
str6: .asciiz " number\t"
str7: .asciiz " raised to the power of "
error1message: .asciiz "Array limit cannot exceed 10, try again:\n"
error2message: .asciiz "Array is not between 1-12, Try Again:\n"
output: .asciiz "Product of numbers is: "
newline: .asciiz "\n"
.text
li $v0, 4
la $a0, str1
syscall
li $v0, 4
la $a0, str2
syscall
li $v0, 4
la $a0, str3
syscall
li $s3, 0
li $s4, 12
la $s1, myarray
li $s0, la
arraylimit:
li $v0, 4
la $a0, str4
syscall
li $v0, 4
la $a0, newline
syscall
li $v0, 5
syscall
add $s1, $v0, $0 #storing into $s1 the array limit value
ble $s1, $s3, error1
bge $s1, $s4, error1
arrayvalue:
li $v0, 4
la $a0, str5 # "Enter "
syscall
li $v0, 4
la $a0, str6 #"number"
syscall
li $v0, 5
syscall
add $s2, $v0, $0 #storing into $s2 thearray value
ble $s2, $s3, error2
bge $s2, $s4, error2
li $s5, 0
addi $s6, $0, 1
inloop:
li $v0, 4
la $a0, newline
syscall
beq, $s0, $0, next
li $v0, 5
syscall
sw, $v0
addi $s1, $s1, 4
addi $s0, $s1, -1
li $v0, 4
la $a0, newline
syscall
j inloop
error1: li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, error1message
syscall
j arraylimit
error2:
li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, error2message
syscall
j arrayvalue
exit: add $a0, $s1, $0
li $v0, 1
syscall
li $v0, 4
la $a0, str7
syscall
add $a0, $s2, $0
li $v0, 1
syscall
li $v0, 4
la $a0, output
syscall
add $a0, $s6, $0
li $v0, 1
syscall
li $v0, 10
syscall
next:
li, $s0, 10 #update loop counter
la, $s0, myarray
outloop:beq $s0, $0, done
la $a0, 0($s1)
li $v0, 1
syscall
addi $s1, $s1, 4
addi $s0, $s0, -1
j outloop
To display the reverse array in assembly, you can use a loop to iterate through the array and print out the values in reverse order. Here's an example of how you modify your code to achieve this:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps