Page 1 of 1

Strange problem - no call to function?

Posted: Tue May 18, 2010 1:42 am
by itportal
Hello everyone,

I am trying to compile a simple function, that calls the BIOS to make some output on the screen. The code runs in real mode and the function looks like this:

Code: Select all

void mprint(const char* text)  {	
	while(*text){
		asm volatile("int 0x10" :  : "a" (  (0x0E << 8) | *text ) : "ebx", "ecx", "edx" );
		text++;
	}
}
The code is compiled with following options:
-m32 -march=i386 -O0 -Wall -include 16bit.h -masm=intel -nostdlib -c

where 16bit.h adds the .code16gcc section.

When I make a call to this function in my main, no call is actually produced in the assembled machine code (which of course results in no text output). However, when I remove the -march=i386 option, the calls are correctly produced. This is somehow strange, because I have several other functions as well and the calls to them compile correctly in both cases.

Any ideas what I am missing?

PS. The function itself is compiled and assembled correctly, but no call to it at all.

Re: Strange problem - no call to function?

Posted: Wed Jul 28, 2010 1:55 am
by Chandra
Try giving function prototype like this:

static char character; /* I have just used name character you can use any other name*/

void print(const char message[30]); /*this is just an example not your real code*/

void main()
{
char message[30]={"Function test successfull"};
print(message);
for(;;);
}

void print(const char message[30])
{
int char_number=0;
for(char_number=0;char_number<30;char_number++)
{
character=message[char_number];
if(character==0) break;
asm("mov al,[_character]\n\
mov bl,0\n\
so on.....to set text attributes and color. Then call the int 10;
int 0x10\n");
}
}

I had encountered similar type of problem but I had finally found this solution. Try it, that should work. And of course you must use masm=intel switcha as well as -ffreestanding to compile this correctly.

Re: Strange problem - no call to function?

Posted: Wed Jul 28, 2010 1:18 pm
by Firestryke31
Use

Code: Select all

 tags and people will be less likely to simply skip over this post.