calling assembly code from C

i have found numerous tutorials on the internet, that briefly go over this subject, but even copying examples word for word, i cant get it to work. This may be because the C and assembly code are parts of an operating system i am developing, the problem is that it doesnt do what it should, and it gives me a horrible error.

i am using the GCC compiler
the nasm assembler
and botchs

this is the c code
//kernel.c
#include "video.c"
extern void user_input();

int main()
{
write("welcome to zack OS!
please enter your

commands",(char*)0xb8000,0x08);

user_input();

//int i=0;
//while (i=0) //indefinate hang
//{
// i=0;
//}
return 0;
}

void _alloca()
{

}

void __main()
{

}

this is the assembly code ( i removed the stuff that did anything, in case it was cauing a problem)
global _user_input
_user_input:
push ebp
mov ebp,esp
pop ebp
ret

any help on this would be appreciated, as it is driving me up the wall, thanks

Comments

  • : i have found numerous tutorials on the internet, that briefly go
    : over this subject, but even copying examples word for word, i cant
    : get it to work. This may be because the C and assembly code are
    : parts of an operating system i am developing, the problem is that it
    : doesnt do what it should, and it gives me a horrible error.
    :
    : i am using the GCC compiler
    : the nasm assembler
    : and botchs
    :
    : this is the c code
    [code]
    : //kernel.c
    : #include "video.c"
    : extern void user_input();
    :
    : int main()
    : {
    : write("welcome to zack OS!
    please enter your
    :
    : commands",(char*)0xb8000,0x08);
    :
    : user_input();
    :
    : //int i=0;
    : //while (i=0) //indefinate hang
    : //{
    : // i=0;
    : //}
    : return 0;
    : }
    :
    : void _alloca()
    : {
    :
    : }
    :
    : void __main()
    : {
    :
    : }
    [/code]
    :
    : this is the assembly code ( i removed the stuff that did anything,
    : in case it was cauing a problem)
    [code]
    : global _user_input
    : _user_input:
    : push ebp
    : mov ebp,esp
    : pop ebp
    : ret
    [/code]:
    : any help on this would be appreciated, as it is driving me up the
    : wall, thanks
    :

    Please use code tags.

    Have a look at the assembly output of your code. (-S switch in gcc)
    (and if you succed, post it here)

    Does removing the call to user_input make the code work?

    Also try
    extern void user_input(void);
  • I tried entering the "void" where you said to, and it still did the same thing, however, i did try moving the code to the very begining of the first asm file (placing it before the code that calls the main OS code, and this gave a different result and didnt crash....but still not the expected result.

    also i did try assembling the code, although the code posted is obviously just the assembled C code, of the kernel, i have included it as an attatchment.
  • : I tried entering the "void" where you said to, and it still did the
    : same thing, however, i did try moving the code to the very begining
    : of the first asm file (placing it before the code that calls the
    : main OS code, and this gave a different result and didnt
    : crash....but still not the expected result.
    :
    : also i did try assembling the code, although the code posted is
    : obviously just the assembled C code, of the kernel, i have included
    : it as an attatchment.
    :

    Again, are you sure it's not the write func that crashes it?

    Maybe you should try using inline assembly, like this:
    [code]
    asm("mov ebp,esp");
    [/code]
  • i have tried removing the write function, and it does change the outcome, instead of crashing it does complete however i tried to make the _user_input method write a char to the screen, and it doesn't even when it is the only thing that the main() method does, which implies that the code isnt being called, as i tried to make it just hang and that didnt work either.

  • oops double post sorry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories