Thread: Is there a way to ask for a register and GUARANTY that I'll get it?

  1. #1
    Registered User
    Join Date
    Oct 2021
    Posts
    138

    Is there a way to ask for a register and GUARANTY that I'll get it?

    I'm interesting in founding a way (if any) to guaranty that I'll ask for a specific register and that I'll get it. I want the compiler to ignore this register and not use it for the rest of the program (or scope). I know about the "register" keyword but from what I heard, it does "hint" the compiler but doesn't for it to give you a register. I want something that will guarentty that I'll get a specific register and that I'll be able to safely using it (where "safely" means that the compiler will not modify its value).

    For anyone that will ask why to do that. I know that the compiler already does the best job using registers but I want to use TCC (which doesn't) as a backend for my code generation and write inline assembly instead of output assembly and then using "GAS" and "LD" to link. And why I want to do that? Well because TCC compiles 2-3 times faster than the time needed for "GAS" + "LD".

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Which compiler are you talking about?

    For GCC, there is '-mfixed-range'

    But TBH, you'd be better off doing save/restore in your own ASM, than crippling 99% of the code because it had one register less to play with.

    Also, just excluding a register in your compiled code says nothing about whether any libraries you link with, which would be free to use that same register.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2021
    Posts
    138
    Quote Originally Posted by Salem View Post
    Also, just excluding a register in your compiled code says nothing about whether any libraries you link with, which would be free to use that same register.
    ........! I didn't thought about that! Then I'm back into learning Assembly and Machine language (and ELF of course). Tbh, after I posted this, I found some articles and a great repo on Github that helped my understand the program header and the segments and I'm able to move on. Thanks a lot however! It seems to me that I have decided that I want to do it this way and I thought bad about giving up and trying something else. So yeah, thanks for your time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Register in C - ADT
    By brCode in forum C Programming
    Replies: 2
    Last Post: 10-20-2016, 03:32 PM
  2. EIP register
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2008, 03:41 AM
  3. register bug
    By avgprogamerjoe in forum C++ Programming
    Replies: 8
    Last Post: 07-10-2007, 02:27 PM
  4. moving byte pointed to by contents of a register into another register. dos debug.
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-18-2003, 05:48 PM
  5. do we have to re-register
    By iain in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-11-2001, 08:00 AM

Tags for this Thread