Asznee Joneson
Asznee Joneson

Reputation: 1

I'm attempting to convert a program from C to MIPS Assembly, receive an infinite loop

When the input to this program is "1 216", this assembly code written in a basic-level of MIPS seems to enter an infinite loop, never stopping. Following is the C code I'm attempting to convert:

#include <stdio.h>

int number= 0;
int exponent= 0;
int result= 0;

Upvotes: 0

Views: 121

Answers (1)

Erik Eidt
Erik Eidt

Reputation: 26766

sopd calls power in a loop.

This loop in sopd relies on $t0, $t1, $t2, and $t3.

power repurposes $t0, $t1, $t2, and $t3.

power returns to sopd, and those registers no longer have the expected values.


This would be highly visible during single stepping.


Hint: for debugging & testing, start with the smallest input values, then slowly increase them to engage more of the program.  Single step through all new code and verify that (1) registers and (2) memory and (3) flow of control are all doing what you expect.


The calling convention is bizarre to say the least.

It uses Full Descending on prologue and epilog, yet Empty Descending for parameter passing — that's weird, but by avoiding using 0($sp) as an available stack location in the functions, at least this doesn't seem to be causing problems.

The code is dynamically pushing and popping the stack, plus using a frame pointer, when the stack could be managed entirely with static analysis, which is the norm for MIPS.

It is passing parameters on the stack, when the norm for MIPS is to use registers for parameters.

It using the $t registers as if they were call preserved, but they are neither designated as call preserved, nor is the code saving/restoring them.

It is frequently storing values & variables into the stack, but never reloading them from the stack.

Upvotes: 2

Related Questions