Using saved registers at the main function with no other function calls [RISC-V] The convention when a function is going to use a saved register is to save the contents of that register to the stack in case the caller (if there's one? the main function doesn't have one) had been using this register too and to restore the contents right before returning. Is this convention always obeyed? In the case of a really simple program, with just a main function and no other function calls, would the compiler prefer to optimize and disobey the convention, which means no saving before using the saved register? Of course, a convention is not a rule so i was wondering in which situations can these not be followed?
Calling conventions may be called &quot;convention&quot;, but they are rules. The reason they are called &quot;convention&quot; is because each compiler uses a different one, once a convention was chosen - it acts as rules.
Regarding the particular case of &quot;main&quot;, it's being called by the operating system, so convention must be obyed.