Page 1 of 1

[help] problem on printing message

Posted: Sat Mar 03, 2007 10:35 am
by secondtptong
Hi all,

I just try to build a simple kernel from the online tutor...

but there is problem to print the string ( it is ok to print a single charater)
below is the code:

Code: Select all

void putch(unsigned char c) // this function is to print a single character
                                        // and work fine
but the following function "puts()" doesnt work when I define the variable as:unsigned char text[]="hello";

if I define it as :
static unsigned char text[]="hello";// work

unsigned char text[]={'h','e','l','l','\0'}; //work

Code: Select all

void puts(void)
{
    int i;

[b]   

  //   unsigned char text[]="hello"; //cannot print the message
    
 //   static unsigned char text[]="hello";// work 
    
   // unsigned char text[]={'h','e','l','l','\0'}; //work
[/b]


    for (i = 0; i < strlen(text); i++)
    {
        putch(text[i]);
    }
}


void main(void)
{


 puts();


}




Thanks in advance

puts("Heres what i think");

Posted: Sat Mar 03, 2007 11:03 am
by salil_bhagurkar
Ok declaring as text[]="hello" worked fine with my putch. You can try the following code:
Instead of putch(text) in puts code try putch(*(text+i)) or
putch(*text);
text++;

And are u passing text to puts? like puts(text). y is puts as puts(void)?

Re: puts("Heres what i think");

Posted: Sat Mar 03, 2007 11:27 am
by secondtptong
salil_bhagurkar wrote:Ok declaring as text[]="hello" worked fine with my putch. You can try the following code:
Instead of putch(text) in puts code try putch(*(text+i)) or
putch(*text);
text++;

And are u passing text to puts? like puts(text). y is puts as puts(void)?


the original code is :

Code: Select all

void puts(unsigned char *text)
{
    int i;

    for (i = 0; i < strlen(text); i++)
    {
        putch(text[i]);
    }
}


void main()
{
    int i;

    gdt_install();
    idt_install();
    isrs_install();
    irq_install();
    init_video();
    timer_install();
    keyboard_install();

    __asm__ __volatile__ ("sti");

    puts("Hello World!\n");


    for (;;);
}


but it cannt print the "hello world" by " puts("Hello World!\n"); "
unless I use

Code: Select all

    static unsigned char text[]="hello";// work 
    or
    unsigned char text[]={'h','e','l','l','\0'}; //work 
    puts(text);
thx.....

Posted: Sat Mar 03, 2007 11:36 am
by urxae
By "the online tutor", you wouldn't happen to mean "Bran's Kernel Development Tutorial", would you? It's a good tutorial, but it's missing the .rodata section in the linker script. That causes all sorts of trouble with strings...

See: http://www.osdev.org/phpBB2/viewtopic.php?p=89526#89526

Posted: Sat Mar 03, 2007 11:40 am
by secondtptong
urxae wrote:By "the online tutor", you wouldn't happen to mean "Bran's Kernel Development Tutorial", would you? It's a good tutorial, but it's missing the .rodata section in the linker script. That causes all sorts of trouble with strings...

See: http://www.osdev.org/phpBB2/viewtopic.php?p=89526#89526
exactly right, it is that tutorial..:p


thanks u so much !!!