Before I begin, it should be noted that the reason I am making this algorithm is for the sole purpose of manually translating it to assembly as a programming excersize.
I'd like to optimize this algorithm if possible - this is a single C function which should return a string representing a number. The string won't print with printf at the moment, however, this isn't a problem as the function i use in assembler to print the string is very different from printf.
int int2str(unsigned int num, unsigned int *string)
unsigned int digits, x, y, z, n = 0;
//find the total number of digits.
for (digits = 0; exponent(digits, 10) <= num; digits++)<br /> ;
//for each digit, find the digit's value and add it to
for (x = digits; x >= 1; x = x-1)
//find the value of the largest digit
y = num;
z = x;
// ">>" until only one digit is left
while (z >= 2)
z = z-1;
//add the digit to the string
string[n] = y+48;
n++; //increment the character index
//remove the largest digit from num
num = num-(y*exponent(x-1, 10));
string [n] = 0;
//exponent was used elsewhere. This function returns x to the nth power:
int exponent(int x, int n)
Thanks for any help you may be able to offer! I'll be honest, i'm not a C expert, i am much more interested in learning assembler.
Jakykong (Jack Mudge)[email protected]