Assembly, Call function through Register

Programming, for all ages and all languages.
Post Reply
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Assembly, Call function through Register

Post 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?
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

Re: Assembly, Call function through Register

Post by Dario »

...and what happens to registers and stack after _isrhandler returns?
Hint: Intel manual vol. 3A, chapter 6.12.1, figure 6-4.
____
Dario
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Assembly, Call function through Register

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Assembly, Call function through Register

Post 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.
Post Reply