• Getting a free registration in code emmiter

    From erwin.matthijssen@gmail.com@21:1/5 to All on Mon Mar 13 10:21:14 2017
    On my architecture I need 3 instructions to do a call:

    Add reg, pc, 2
    Push reg
    Br <label>

    I could handle this in various places in the description file. However, I need a free register to temporarily hold the value to push. Is there a function available in the back end that will return a free register?

    I know one solution is to dedicate a register for this. But that seems a waste of a reg (of which I have precious few).

    Any insight is appreciated,
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From erwin.matthijssen@gmail.com@21:1/5 to All on Mon Mar 13 11:38:00 2017
    With a bit more thinking, I might have solved my own problem:

    Since we are calling a new function, all registers are about to get freed anyway. So I could use any of the temp register since their values are not going to be used anymore.

    Apologies for the premature posting..
    Erwin

    Op maandag 13 maart 2017 18:21:15 UTC+1 schreef erwin.ma...@gmail.com:
    On my architecture I need 3 instructions to do a call:

    Add reg, pc, 2
    Push reg
    Br <label>

    I could handle this in various places in the description file. However, I need a free register to temporarily hold the value to push. Is there a function available in the back end that will return a free register?

    I know one solution is to dedicate a register for this. But that seems a waste of a reg (of which I have precious few).

    Any insight is appreciated,
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jacob navia@21:1/5 to All on Thu Mar 16 00:26:37 2017
    Le 13/03/2017 à 19:38, erwin.matthijssen@gmail.com a écrit :
    Add reg, pc, 2
    Push reg
    Br <label>

    Calling conventions

    Better would be to write only

    add reg0,2
    br <label>

    And in the called function do a push if necessary.
    This way you save a push in all call sites and place the push only once
    in the called function. That saves code space.

    The return address could be placed always in the first register, where
    the result will be returned. It should be a free register anyway.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From erwin.matthijssen@gmail.com@21:1/5 to All on Mon Apr 10 03:48:02 2017
    @jacob thx for this!

    It took me a bit to understand why this would make a difference, but I get it: a function is often called more than once in a program.

    Good advice, thx again!
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)