Why does IA-32 have a non-intuitive caller and callee register saving convention?

前端 未结 4 1322
借酒劲吻你
借酒劲吻你 2020-12-03 13:20

The common calling conventions for IA-32 say:

• Callee-save registers
%ebx, %esi, %edi, %ebp, %esp
Callee must not change these.  (Or restore the caller\'s v         


        
4条回答
  •  醉梦人生
    2020-12-03 13:45

    A guess:

    If the caller saves all registers it will still need after a function call, it wastes time when the called function doesn't modify all those registers.

    If the callee saves all registers it changes, it wastes time when the caller didn't need the values in those registers again.

    When some registers are saved by caller and some by callee, the compiler (or assembly programmer) can choose which kind to use depending on if the value is needed after the next function call.

提交回复
热议问题