Page 1 of 1

Assembly, Call function through Register

Posted: Fri Mar 11, 2011 4:00 am
by mark3094
I am writing a kernel in C and assembly. The main function is written in C, and some hardware specific functions are in assembly.

I have the IDT setup to call assembly functions. Some of these then call a C function.

This is the code I use to call the C function:

Code: Select all

mov eax, _isrhandler
call eax
Normally I would just use

Code: Select all

call _isrhandler
But this doesn't work, and I'm not sure why. I presume it has something to do with the EIP register and pushing it to the stack.

Can anyone explain how this works?

Re: Assembly, Call function through Register

Posted: Fri Mar 11, 2011 5:05 am
by Dario
...and what happens to registers and stack after _isrhandler returns?
Hint: Intel manual vol. 3A, chapter 6.12.1, figure 6-4.

Re: Assembly, Call function through Register

Posted: Fri Mar 11, 2011 6:12 am
by Combuster
The only difference between mov; call; and a regular call is that the former uses an absolute address and the latter a relative address. It means that if a call alone does not work, your code is not executing from the location it was linked at. Are you using a higherhalf model and haven't enabled paging yet?

Re: Assembly, Call function through Register

Posted: Fri Mar 11, 2011 8:09 pm
by mark3094
Thankyou both, I will certainly check out the Intel manual. I welcome the opportunity to research it further, I just needed a point in the right direction :D .

I'm not using the higher-half model (at least I don't think I am, as I don't know a lot about that particular model as yet). So far I only have a boot loader and an 'in construction' kernel that has loaded the GDT and IDT.