I am working on an assembly code that can read a number in base 7, and print it to a base 9 number. The input of the program can be assumed to be a text file with proper base 7 numbers, one on each line.
I have the C code for what im trying to implement, but im unsure how i would go about doing it in assembly...any suggestions or help will be nice. Thank You in advance.
C Code:
Code:
#include <stdio.h>
int main(void)
{
char ch;
unsigned int value;
unsigned int power9;
while (fread(&ch, 1, 1, stdin))
{
value = 0;
// if I am here, I read one character, not at EOF
// and the character is read into ch
do
{
if (ch != '\n')
{
// if I am here, I just read a digit
value = (value * 7) + (ch - '0');
}
else
{
// we are now at the end of line, nothing to do
}
} while ((ch != '\n') && (fread(&ch, 1, 1, stdin) != 0));
// if I am here, we have a value read and interpreted
printf("%u\n",value);
power9 = 9*9*9*9*9;
while (power9 > 0)
{
unsigned quotient;
quotient = value / power9;
ch = quotient + '0';
fwrite(&ch, 1, 1, stdout);
value %= power9;
power9 /= 9;
}
ch = '\n';
fwrite(&ch, 1, 1, stdout);
}
}