Call a function: Difference between revisions
Content added Content deleted
No edit summary |
(add task to ARM64 assembly Raspberry Pi) |
||
Line 46: | Line 46: | ||
CALL (R15),(X,Y) call MULTPLIC(X,Y) |
CALL (R15),(X,Y) call MULTPLIC(X,Y) |
||
ST R0,Z Z=MULTPLIC(X,Y)</lang> |
ST R0,Z Z=MULTPLIC(X,Y)</lang> |
||
=={{header|AArch64 Assembly}}== |
|||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
|||
<lang AArch64 Assembly> |
|||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
|||
/* program callfonct.s */ |
|||
/*******************************************/ |
|||
/* Constantes file */ |
|||
/*******************************************/ |
|||
/* for this file see task include a file in language AArch64 assembly*/ |
|||
.include "../includeConstantesARM64.inc" |
|||
/***********************/ |
|||
/* Initialized data */ |
|||
/***********************/ |
|||
.data |
|||
szMessage: .asciz "Hello. \n" // message |
|||
szRetourLigne: .asciz "\n" |
|||
szMessResult: .asciz "Resultat : " // message result |
|||
/***********************/ |
|||
/* No Initialized data */ |
|||
/***********************/ |
|||
.bss |
|||
sZoneConv: .skip 100 |
|||
.text |
|||
.global main |
|||
main: |
|||
ldr x0,=szMessage // adresse of message short program |
|||
bl affichageMess // call function with 1 parameter (x0) |
|||
// call function with parameters in register |
|||
mov x0,#5 |
|||
mov x1,#10 |
|||
bl fonction1 // call function with 2 parameters (x0,x1) |
|||
ldr x1,qAdrsZoneConv // result in x0 |
|||
bl conversion10S // call function with 2 parameter (x0,x1) |
|||
ldr x0,=szMessResult |
|||
bl affichageMess // call function with 1 parameter (x0) |
|||
ldr x0,qAdrsZoneConv |
|||
bl affichageMess |
|||
ldr x0,qAdrszRetourLigne |
|||
bl affichageMess |
|||
// call function with parameters on stack |
|||
mov x0,#5 |
|||
mov x1,#10 |
|||
stp x0,x1,[sp,-16]! // store registers on stack |
|||
bl fonction2 // call function with 2 parameters on the stack |
|||
// result in x0 |
|||
ldr x1,qAdrsZoneConv |
|||
bl conversion10S // call function with 2 parameter (x0,x1) |
|||
ldr x0,=szMessResult |
|||
bl affichageMess // call function with 1 parameter (x0) |
|||
ldr x0,qAdrsZoneConv |
|||
bl affichageMess |
|||
ldr x0,qAdrszRetourLigne |
|||
bl affichageMess |
|||
// end of program |
|||
mov x0, #0 // return code |
|||
mov x8, #EXIT // request to exit program |
|||
svc 0 // perform the system call |
|||
qAdrsZoneConv: .quad sZoneConv |
|||
qAdrszRetourLigne: .quad szRetourLigne |
|||
/******************************************************************/ |
|||
/* call function parameter in register */ |
|||
/******************************************************************/ |
|||
/* x0 value one */ |
|||
/* x1 value two */ |
|||
/* return in x0 */ |
|||
fonction1: |
|||
stp x2,lr,[sp,-16]! // save registers |
|||
mov x2,#20 |
|||
mul x0,x0,x2 |
|||
add x0,x0,x1 |
|||
ldp x2,lr,[sp],16 // restaur 2 registres |
|||
ret // retour adresse lr x30 |
|||
/******************************************************************/ |
|||
/* call function parameter in the stack */ |
|||
/******************************************************************/ |
|||
/* return in x0 */ |
|||
fonction2: |
|||
stp fp,lr,[sp,-16]! // save registers |
|||
add fp,sp,#16 // address parameters in the stack |
|||
stp x1,x2,[sp,-16]! // save others registers |
|||
ldr x0,[fp] // second paraméter |
|||
ldr x1,[fp,#8] // first parameter |
|||
mov x2,#-20 |
|||
mul x0,x0,x2 |
|||
add x0,x0,x1 |
|||
ldp x1,x2,[sp],16 // restaur 2 registres |
|||
ldp fp,lr,[sp],16 // restaur 2 registres |
|||
add sp,sp,#16 // very important, for stack aligned |
|||
ret // retour adresse lr x30 |
|||
/********************************************************/ |
|||
/* File Include fonctions */ |
|||
/********************************************************/ |
|||
/* for this file see task include a file in language AArch64 assembly */ |
|||
.include "../includeARM64.inc" |
|||
</lang> |
|||
{{output}} |
|||
<pre> |
|||
Hello. |
|||
Resultat : +110 |
|||
Resultat : -90 |
|||
</pre> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||