I am writing an OS in assembly and cpp. I encountered a problem regarding char pointers in cpp: for example, the following code:
#define VIDEO_MEMORY 0xB8000
#define COLUMNS 80
#define ROWS 25
#include "screen.h"
#include <stdint.h>
const char scancodes[] = {'\0','%','1','2','3','4','5','6','7','8','9','0',
'-','=','~','\t','Q','W','E','R','T','Y','U','I','O','P','[',']','\e','\0','A', 'S','D',
'F','G','H','J','K','L',';','\0','`',
'\0','\\','Z','X','C','V','B','N','M',',','.',
'/','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
'\0','\0','\0','\0','\0','\0','\0','\0','-','\0','\0','\0','+','\0','\0','\0','\0','~',};
void print_keyboard(int code)
{
set_char_at_video_memory(scancodes[code], 0);
}
void main() {
clear_screen();
set_char_at_video_memory('h', 0);
while(1)
{
__asm__("hlt");
}
}
works perfectly but when I slightly change it so that now I use char pointers (strings) the code no longer seems to work. It is as though the condition turns out false.
#define VIDEO_MEMORY 0xB8000
#define COLUMNS 80
#define ROWS 25
#include "screen.h"
#include <stdint.h>
const char scancodes[] = {'\0','%','1','2','3','4','5','6','7','8','9','0',
'-','=','~','\t','Q','W','E','R','T','Y','U','I','O','P','[',']','\e','\0','A', 'S','D',
'F','G','H','J','K','L',';','\0','`',
'\0','\\','Z','X','C','V','B','N','M',',','.',
'/','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
'\0','\0','\0','\0','\0','\0','\0','\0','-','\0','\0','\0','+','\0','\0','\0','\0','~',};
void print_keyboard(int code)
{
set_char_at_video_memory(scancodes[code], 0);
}
void main() {
clear_screen();
const char* c = "hello";
if (c[0] == 'h')
set_char_at_video_memory('h', 0);
while(1)
{
__asm__("hlt");
}
}
this is my linker script:
ENTRY(main)
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 0x1000; /* Set the starting address of the kernel */
.text : { *(.text) } /* Code section */
.rodata : { *(.rodata) } /* Read-only data section */
.data : { *(.data) } /* Initialized data section */
.bss : { *(.bss) } /* Uninitialized data section */
/DISCARD/ : { *(.eh_frame) } /* Discard unnecessary sections */
}
I've tried altering my linker file to no success. If anyone could help me solve this issue I would be very grateful.