Page 1 of 1

string trouble

Posted: Tue Sep 02, 2003 11:00 pm
by nicky_girl
Ok Guys,

I have written a putchar function in assembly which I call through my C kernel.  It works fine as long as I don't try to print a string.  For instance...

char y = 'y';
char *ptr = &y;

putchar (y, 0xb8000);      //prints a 'y'
putchar (*ptr, 0xb8002);   //prints another 'y'

char *word = "hello";

putchar(*word, 0xb8004);   //this should print a 'h' but it doesn't

In fact it just prints a blank.  If anybody has any ideas I'd love to hear them....Thanx

-Nicole

RE:string trouble

Posted: Tue Sep 02, 2003 11:00 pm
by carbonBased
Try this:
putchar(&word[0], 0xb8000);

Cheers,
Jeff

RE:string trouble

Posted: Wed Sep 03, 2003 11:00 pm
by Xenos
Try this:
putchar(word[0], 0xb8000);

It seems your putchar needs the char, not its address...

RE:string trouble

Posted: Wed Sep 03, 2003 11:00 pm
by nicky_girl
Well I've tried both methods that were suggested and they don't seem to work.  I did try just moving my methods to a regular application program for Linux.  And it works fine.  It almost seems like when I try to pass the char* to a subroutine the address that the string is written at is lost somehow.  But I can't think of why this would occur.  Thanks again.

-Nicole

RE:string trouble

Posted: Wed Sep 03, 2003 11:00 pm
by knicos
Any chance of seeing the assembly code?

I dont know anything of your kernel:
Is this the last piece of code in the kernel (are there any variables after it?).
How is the kernel loaded, because mine is loaded using bios and I only load 50Kb, if my OS exceeds that then some of the data (ie the string) isn't loaded and you will get blanks.
Finally, if none of the above applies, then it could be something to do with your stack setup, it may not be big enough, or (more likely) it overwrites the data section of your code.

Cant think of anything else, until i see code.

RE:string trouble

Posted: Thu Sep 04, 2003 11:00 pm
by rexlunae
This isn't really related to your problem, but couldn't you skip writting an assembly function and instead just code lines like this:

*(char *)0xb8000 = y;
instead of this:
putchar (y, 0xb8000);      //prints a 'y'

I would do it that way if possible because it is easier to make errors interfacing to assembly routines.

RE:string trouble

Posted: Thu Sep 04, 2003 11:00 pm
by mr. xsism
We need to see your putchar() function.

I would try this:
char *word = "hello";

putchar(word[0], 0xb8004);

Here's a simplified version of mine:
void putch(char ch)
{
VIDMEM[((ROW*80*2)+(COL*2))] = ch;
VIDMEM[((ROW*80*2)+(COL*2))+1] = ATTRIB;
COL++;
if(COL>=80)
{
ROW++;
COL=0;
}
if(ROW>=25)
{
ROW=0;
}
move_cursor(COL,ROW);
}

- - -
COL,ROW, & ATTRIB are global vars.

I hope that helps.

Regards,
mr. xsism