字符串文字在传递给函数时变成空字符

问题描述

我正在制作一个简单的内核,我遇到了将字符串文字作为 char* 传递给函数的问题。

从传递给函数的字符串中打印任何字符会导致空字符,我测试了这个我打印的第一个字符 + 48,它打印了 0。我不确定天气这可能是由于我的命令用于编译,我正在编译以下 GCC 标志 -fno-stack-protector -mgeneral-regs-only -mno-red-zone -ffreestanding -fno-pie -m32 -nostdinc -nostdlib

我已通过编译为程序集来检查字符串文字是否在程序集中。

文件

#include "../drivers/ports.h"
#include "../drivers/screen.h"

void main()
{
    clear_screen();

    kprint_at("hhgfhehthdtydhgf",1,6);
    /*
    kprint_at("This text spans multiple lines",75,10);
    kprint_at("There is a line\nbreak",20);
    kprint("There is a line\nbreak");
    kprint_at("What happens when we run out of space?",45,24);
    */
}

在 screen.c 文件

void kprint_at(char *message,int col,int row)
{
    print_char(message[0] + 48,col,row,WHITE_ON_BLACK); // prints a 0 to the screen,ascii 48

    int offset;
    if (col >= 0 && row >= 0)
    {
        offset = get_offset(col,row);
    }
    else
    {
        offset = get_cursor_offset();
        row = get_offset_row(offset);
        col = get_offset_col(offset);
    }

    int i = 0;
    while (message[i] != 0)
    {
        offset = print_char(message[i++],WHITE_ON_BLACK);
        row = get_offset_row(offset);
        col = get_offset_col(offset);
    }
}

我已经验证了从 kprint_at 函数调用的所有函数的正确操作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)