Hello Sir, I am using DELL laptop and with the help of QEMU, NASM and GCC i am trying to compile a simple code which is not executing properly. I am using UBUNTU 10.04.

here is the loader.asm assembly file.

global 	loader
extern 	dmain
MODULEALIGN		equ 1<<0
MEMINFO 			equ 1<<1
FLAGS equ 	MODULEALIGN | MEMINFO
MAGIC  equ		0x1BADB002
CHECKSUM 	equ  -(MAGIC + FLAGS)
section .text
align 	4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM


STACKSIZE 	equ 0x4000
loader:
mov 	esp, stack+STACKSIZE
push 	eax
push 	ebx


call dmain
cli


hang:
hlt
jmp hang


section .bss

align 	4

stack :

resb STACKSIZE

$nasm -f elf loader.o loader.asm

my c program kernel.c

void dmain(void* mbd ,unsigned int magic)
{
	if(magic !=0x1BADB002)
	{
		clr();
		print("Error:Invalid Number",0xAF);
		
	}
	else
	{
		clr();
		print("Hello World",0xAF);
		
	}
}


void print(char* msg,int color)
{
	char* mem=(char*) 0xB8000;
	while(*msg !=0)
	{
		*mem=   *msg;
		mem++;
		msg++;
		*mem=(char*)  color;
		mem++;
	}
}

void clr(void)
{
	char* mem=(char*) 0xB8000;
	while(*mem !=0)
	{
		*mem = 0;
		mem++;
	}
}

$gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs

linker prorgram linker.ld

ENTRY(loader)
SECTIONS{
	. =0x00100000 ;
	.text :{
		*(.text)
	}
	.rodata ALIGN (0x1000) :{
		*(.data)
	}
	.bss : {
		sbss =  .;
		*(COMMON)
		*(.bss)
		ebss = .;
	}
}

$ld -T linker.ld -o kernel.bin loader.o kernel.o

$qemu -kernel -kernel.bin

in the output part of QEMU , nothing is displayed. I tried to find error but i am not getting it, Its also not like that its not addressing video memory as in my output clr() is working and clearing the screen but print() is not working it should give output:- Error:Invalid Number.
I am not getting the error, Please help me out..:(

Don't you need to link GRUB (or whatever multi-boot loader you're using) into your image as well?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.