using registers rbx, r12-15

  • Follow


Hi all,

I am writing a program for x86-64 linux in assembly.

I am writing code to be use without any libraries or startup code at all, 
using gcc -nostdlib.

I understand that according to the ABI registers rbx and r12-15 cannot be 
clobbered by called functions, but I want to use them within my program.

My program does not have a main() function, but simply a label _start.

According to the ABI <http://www.x86-64.org/documentation/abi.pdf> these 
registers have no particular value at process startup.  Can I therefore 
use them with impunity, or are they used in some way that I don't know 
about (kernel perhaps)?

I have read that r15 is used in PIC, but I'm not writing a shared library.

The functions I have written follow the ABI and don't clobber these 
registers, but I would like to use them in my equivalent of main.

Thanks,
viza

0
Reply viza 11/27/2008 4:08:45 PM

On Thu, 27 Nov 2008 16:08:45 GMT
viza  <spamtrap@crayne.org> wrote:

> I understand that according to the ABI registers rbx and r12-15
> cannot be clobbered by called functions, but I want to use them
> within my program.

To begin with, don't clobber doesn't mean don't use. The only
requirement is that, if your code is called by another program, you
must restore the original values before returning to the caller.
Programs, such as yours appears to be, which receive control from, and
exit back to, the OS, do not need to save or restore any registers.

In addition, for calls to your own subroutines, you can ignore the ABI
entirely, and invent your own calling and return conventions.

-- 
Chuck 
http://www.pacificsites.com/~ccrayne/charles.html


0
Reply Chuck 11/27/2008 8:41:27 PM


Chuck Crayne  <spamtrap@crayne.org> writes:
> On Thu, 27 Nov 2008 16:08:45 GMT
> viza  <spamtrap@crayne.org> wrote:
>
>> I understand that according to the ABI registers rbx and r12-15
>> cannot be clobbered by called functions, but I want to use them
>> within my program.
>
> To begin with, don't clobber doesn't mean don't use. The only
> requirement is that, if your code is called by another program, you
> must 

_they_ must

> restore the original values before returning to the caller.

Phil
-- 
I tried the Vista speech recognition by running the tutorial. I was 
amazed, it was awesome, recognised every word I said. Then I said the 
wrong word ... and it typed the right one. It was actually just 
detecting a sound and printing the expected word! -- pbhj on /.

0
Reply Phil 11/27/2008 9:48:39 PM

On Thu, 27 Nov 2008 23:48:39 +0200
Phil Carmody <thefatphil_demunged@yahoo.co.uk> wrote:

> _they_ must

In this particular case, he IS the "they".

-- 
Chuck 
http://www.pacificsites.com/~ccrayne/charles.html


0
Reply Chuck 11/27/2008 11:46:05 PM

Chuck Crayne  <spamtrap@crayne.org> writes:
> On Thu, 27 Nov 2008 23:48:39 +0200
> Phil Carmody <thefatphil_demunged@yahoo.co.uk> wrote:
>
>> _they_ must
>
> In this particular case, he IS the "they".

Wow. Dunno what my eyes were doing when they read the original. Sorry.

Phil
-- 
I tried the Vista speech recognition by running the tutorial. I was 
amazed, it was awesome, recognised every word I said. Then I said the 
wrong word ... and it typed the right one. It was actually just 
detecting a sound and printing the expected word! -- pbhj on /.

0
Reply Phil 11/28/2008 2:35:06 AM

4 Replies
138 Views

(page loaded in 0.111 seconds)


Reply: