Original Post
Hi guys. After trying to make more complicated programs in assembly I came across the same problem again and again: running out of registers. How should I compensate for this? I use push and pop to save and restore registers, and this way have more of them to use, but is there a better way? How should I use the stack to overcome this problem? What operations/instructions affect the ESI and EDI registers? Example: I'm trying to raise 1 complex number at a given power n. I run out of registers while doing this. The C++ version of the program would look like this: But writing all this in assembly tends to complicate things(because I'm a begginer and all :) ) How should I solve the "run out of registers" problem elegantly and efficiently :), well if that asks too much, how should I solve it in the easiest way possible?
#include <iostream>
#include <stdlib.h>
using namespace std;
class Complex
{
public:
Complex();
Complex(int r, int i)
{
re = r;
im = i;
}
Complex power(int n)
{
int r = re;
int i = im;
while (n>1)
{
int tre = re;
re = re*r - im*i;
im = tre*i + im*r;
n--;
}
return *this;
}
int re, im;
};
ostream& operator << (ostream& o, Complex c)
{
o << c.re << " " << c.im << endl;
return o;
}
int main()
{
Complex a(1,1);
a.power(10);
cout << a;
return 0;
}