Return multiple values: Difference between revisions

m
Line 297:
When programming without any rules governing the way you write functions, a function's "return value" is nothing more than the register state upon exit. However, the [https://www.eecs.umich.edu/courses/eecs373/readings/ARM-AAPCS-EABI-v2.08.pdf AAPCS] calling convention dictates that the <code>R0</code> register is used to store a function's return value. (If the return value is larger than 32 bits, the registers <code>R1-R3</code> can also be used.) Following this standard is necessary for human-written assembly code to properly interface with code written by a C compiler.
 
This function takes two numbers in <code>R0</code> and <code>R1</code>, and returns their sum in <code>R0</code> and their difference in <code>R1</code>.
<lang ARM Assembly>sum:
 
;int sum(int a,int b){return a+b;}
<lang ARM Assembly>sumfoo:
;takes R0 and R1 as arguments, outputs their sum to R0.
ADDMOV R0R2,R0,R1
MOV R3,R1
bx lr</lang>
ADD R0,R2,R3
SUB R1,R2,R3
bxBX lrLR</lang>
 
=={{header|Arturo}}==
1,489

edits