-2
\$\begingroup\$

I learnt that in RiscV assembly we save function arguments in registers s0,...,s7 but what if I had more that 8 arguments?

Plus what about the case where I have more than 32 arguments (let's say 40) how this is managed?

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Your other account is still in suspension. I don't appreciate you circumventing your suspension. \$\endgroup\$ – Marcus Müller Jan 22 at 11:04
  • \$\begingroup\$ That isn't my other account! \$\endgroup\$ – albert Jan 22 at 14:34
  • 1
    \$\begingroup\$ Albert, do you think I'm stupid. This account that you're using here is suspended over at stackoverflow for violating suspension rules here (and you had the audacity to complain on meta about people not answering within 3hrs of posting the question, and then about people closing the question for content reasons as well as community rule reasons). Now you lie. Thank you for making clear how you plan to approach this, I will not react to you in any further way. \$\endgroup\$ – Marcus Müller Jan 22 at 14:47
  • \$\begingroup\$ accounts are linked through stackexchange, I thought you'd have figured that out while copying over questions... \$\endgroup\$ – Marcus Müller Jan 22 at 14:56
0
\$\begingroup\$

The calling convention explains the behavoir.

The RISC-V calling convention passes arguments in registers when possible. Up to eight integer registers, a0–a7, and up to eight floating-point registers, fa0–fa7, are used for this purpose.

More will be passed by stack.

Though, 40 arguments to a function may also be a sign of bad code.
How about passing a struct or array pointer?

\$\endgroup\$
3
  • \$\begingroup\$ "More will be passed by stack." can you show an example? how could the could function "understand" that its arguments are if memory this time instead of registers? \$\endgroup\$ – albert Jan 22 at 10:25
  • 2
    \$\begingroup\$ If the compiler generated the code, it knows where things are. If you wrote the code, then you know where things are. If the function expects 40 variables, the whoever wrote that function knows you can't pass 40 vars in registers. \$\endgroup\$ – Kartman Jan 22 at 10:37
  • 1
    \$\begingroup\$ @albert Calling and called functions understand each other by convention. It's like in real life. \$\endgroup\$ – the busybee Jan 22 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.