Hello, I am supposed to write a code in MIPS to do the following below. Basically, you enter an integer,
and it should check to see if it is a palindrome, and if not it will output the number, and keep adding the
numer backwards to it, outputting it, and stopping when it is a palindrome. It will output 10 numbers
and if the 10th number isnt a palindrome, it stops.

I'm having trouble writing this code in MIPS, i was hoping someone could offer up some ideas?
My main trouble is the loop in the Palindrome function. I believe the code I wrote for the
reverse function works well.

Below is something I quickly wrote as a guideline while writing it into MIPS.

int Reverse(int num)
    int remainder = 0;
    int rev = 0;

    while (num != 0)
        remainder = num % 10;
        num = num/10;
        rev = rev*10 + remainder;
    return rev;

void Palindrome()
    int num;

    cin >> num;
    cout << num;
for (int i = 0; i < 10; i++)
        if ( num != Reverse(num))
        num = num + Reverse(num);
        cout << " " << num;
        if (num == Reverse(num))
        cout << " ";

int main()
    cout << "Please enter an integer : " << endl;

    return 0;
4 Years
Discussion Span
Last Post by DarkLightning7

to make loops in assembly you need to use something similar to the goto function in c.

create a point to "goto". example:

move $t0, $zero  #set $t0 to 0 for your counter.
beq $t0, 10, pos2  #terminate the loop if $t0 equals 10
addi $t0, $t0, 1

#do your calculations here

j pos1            #start the next iteration of the loop

here are a couple pdfs on converting from c to assembly:


as far as reading the number and reversing it it will be much easier to do as a string although the program will use a lot more memory than reading the number as an integer. also one question do you need to find if the number is a palidrome in binary or decimal?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.