构建 16 位操作系统 - 字符数组不起作用

发布于 2024-08-30 10:00:51 字数 729 浏览 3 评论 0原文

我正在构建一个 16 位操作系统。但字符数组似乎不起作用。

这是我的示例内核代码:

asm(".code16gcc\n");
void putchar(char);

int main()
{
char *str = "hello";

putchar('A');
if(str[0]== 'h')
    putchar('h');

return 0;
}


void putchar(char val)
{

   asm("movb %0, %%al\n"  
       "movb $0x0E, %%ah\n" 
       "int $0x10\n"
      :
      :"m"(val)
     ) ;
}

它打印:

A

这意味着 putchar 函数工作正常,但

 if(str[0]== 'h')
        putchar('h');

不起作用。

我正在编译它:

gcc -fno-toplevel-reorder -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0

我应该做什么?

I am building a 16 bit operating system. But character array does not seem to work.

Here is my example kernel code:

asm(".code16gcc\n");
void putchar(char);

int main()
{
char *str = "hello";

putchar('A');
if(str[0]== 'h')
    putchar('h');

return 0;
}


void putchar(char val)
{

   asm("movb %0, %%al\n"  
       "movb $0x0E, %%ah\n" 
       "int $0x10\n"
      :
      :"m"(val)
     ) ;
}

It prints:

A

that means putchar function is working properly but

 if(str[0]== 'h')
        putchar('h');

is not working.

I am compiling it by:

gcc -fno-toplevel-reorder -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2024-09-06 10:00:51

您的数据段可能未加载到目标中。与全新的 kernel.bin 文件(实际上是一个 elf 文件)链接后,您在做什么?

Your data segment is probably not loaded in to the target. What are you doing after the link with your brand new kernel.bin file, which is in fact an elf file ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文