Code:
.data
strPromptFirst: .asciiz "Enter Number: "
strResult: .asciiz "\nThe first n palindromes are: \n"
newLine: .asciiz "\n"
numPalindromes: .word 0
.text
.globl main
main:
#Print String
li $v0, 4
la $a0, strPromptFirst
syscall
#Read in num integers to print
li $v0, 5
syscall
move $s0, $v0 #move that variable to s0
li $t0, 0 #Num palindromes found
li $t1, 11 #Starting palindrome
loop:
bgt $t0, $s0, exit #If numb palindromes have been found, then exit
la $t4, ($t1)
move $a0, $t1
jal palindromes
add $t2, $v0, $zero
bne $t4, $t2, skip #If it's not equal, skip ahead
addi $t0, $t0, 1 #Increment number of palindrome found
li $v0, 1 #Print out number
la $a0, ($t2)
syscall
li $v0, 4 #Print out new line
la $a0, newLine
syscall
j skip
skip:
move $t1, $t4 #Restore value
addi $t1, $t1, 1 #incrememnt original by 1
j loop
palindromes:
addi $sp, $sp, -16
sw $ra, 0($sp)
sw $t0, 4($sp)
sw $t1, 8($sp)
sw $t2, 12($sp)
move $t0, $a0 #Set t0 to equal to starting num
wloop:
beqz $t0, breakLoop
rem $t1, $t0, 10 #t1 = num % 10
div $t0, $t0, 10
mul $t2, $t2, 10 #rem = rem * 10
add $t2, $t2, $t1 #rem = rem + t1
j wloop
breakLoop:
move $v0, $t2
lw $ra, 0($sp)
lw $t0, 4($sp)
lw $t1, 8($sp)
lw $t2, 12($sp)
addi $sp, $sp, 16
jr $ra
exit:
li $v0, 10 # Syscall number 10 is to terminate the program
syscall # exit now
Any help is much appreciated!