L
Lafer
Hello,
I am attempting to write a terminal interface program using PowerPC
Assembly/C, where I am using an integer-to-ASCII conversion algorithm.
Unfortunately, I have run into some difficulties that seem to deal
with the syntax/character types that am I using. Below is a segment of
my code which is intended to convert an integer to an array of ASCII
digits:
The ***** line is where I'm having my problems; presumably adding 48
to a string element (i.e., a character) should convert that value to
its ASCII equivalent so it can be displayed on my terminal screen, but
when debugging the problem line doesn't seem to be doing anything at
all; presumably this is an issue of syntax that you can help me with.
I have also tried '0' and '0x30' in place of 48.
Another problem I have is with copying strings into other strings, for
example I have a help message that says:
strcopy(output, "+ for add, - for subtract, ? for help");
where strcopy is the following function:
When I try to do this conversion it gives me a machine check exception
in the simulator I'm using (SingleStep) something about error, memory
access in 0x0000000D) which it doesn't do if I use a normal strcopy
syntax where a and b are both declared as character pointers e.g. char
*a, char *b. Note that I do not have the standard library, standard
i/o or any other such libraries at my disposal for this program.
If anyone wants to see more of the code or can help me out, please
post a message here or e-mail me. Thanks!
Matt Lafer
University of Michigan
I am attempting to write a terminal interface program using PowerPC
Assembly/C, where I am using an integer-to-ASCII conversion algorithm.
Unfortunately, I have run into some difficulties that seem to deal
with the syntax/character types that am I using. Below is a segment of
my code which is intended to convert an integer to an array of ASCII
digits:
char * inttoascii(int val)
{
int i, temp1, temp2;
i = 0;
char * str;
temp1 = 1;
if(val < 0)
{
str = '-';
val = val*-1;
i++;
}
while(val > temp1)
{
temp1 = temp1*10;
}
while(temp1 >= 10)
{
temp1 = temp1/10;
temp2 = val/temp1;
str = temp2+48; *****
i++;
}
str = '\0';
return(str);
}
The ***** line is where I'm having my problems; presumably adding 48
to a string element (i.e., a character) should convert that value to
its ASCII equivalent so it can be displayed on my terminal screen, but
when debugging the problem line doesn't seem to be doing anything at
all; presumably this is an issue of syntax that you can help me with.
I have also tried '0' and '0x30' in place of 48.
Another problem I have is with copying strings into other strings, for
example I have a help message that says:
strcopy(output, "+ for add, - for subtract, ? for help");
where strcopy is the following function:
void strcopy(char b[], char a[])
{
int i;
for (i = 0; a != '\0'; i++)
b = a;
b = '\0';
}
When I try to do this conversion it gives me a machine check exception
in the simulator I'm using (SingleStep) something about error, memory
access in 0x0000000D) which it doesn't do if I use a normal strcopy
syntax where a and b are both declared as character pointers e.g. char
*a, char *b. Note that I do not have the standard library, standard
i/o or any other such libraries at my disposal for this program.
If anyone wants to see more of the code or can help me out, please
post a message here or e-mail me. Thanks!
Matt Lafer
University of Michigan