0

If I pass two arguments to a function as follows:

loop:
    mov my_array(,%r8d,4), %edi
    mov $2,                %esi
    call some_function
    ...

Do I need to 're-add' the value 2 to %edi every time I call the function if it's static? In other words, can I assume that %esi will not change in a function, or do I need to re-set it before each time I call that function? What's the preferred way to do this in a System V ABI?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
David542
  • 104,438
  • 178
  • 489
  • 842
  • What does the ABI say about this register? Are you linking this with C code? What C compiler generated that code? – old_timer Sep 16 '20 at 03:03
  • @old_timer no I'm just playing around with assembly, i.e., hand-written no compiler. – David542 Sep 16 '20 at 03:11
  • hm, @NateEldredge what does callee-saved mean in this case? Is saved the same thing as "preserved" ? In that the function that is called is not supposed to touch them? Also, could you please link the the page or where it says that? – David542 Sep 16 '20 at 04:14
  • Wait a second, this is 64-bit code. (Please use the [tag:x86-64] tag.) On x86-64, rsi and rdi (including their low halves esi, edi) are NOT required to be preserved across function calls. You will need to reload them after calling the function. [ABI](https://stackoverflow.com/questions/18133812/where-is-the-x86-64-system-v-abi-documented) Figure 3.4, page 23 in my copy. – Nate Eldredge Sep 16 '20 at 04:47
  • Of course, if you have written `some_function` by hand in assembler, then what it does with those registers is whatever you wrote it to do. If it doesn't need to be called by C code, then it is up to you whether to follow the ABI calling conventions or some other. – Nate Eldredge Sep 16 '20 at 04:51
  • Arg-passing registers are call-clobbered in every register-arg calling convention (at least for x86, and generally true across other ISA's calling conventions). – Peter Cordes Sep 16 '20 at 11:55

0 Answers0