/* ARM assembly AARCH64 Raspberry PI 3B */ /* program numfibo64.s */ /*******************************************/ /* Constantes */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64.inc" /*********************************/ /* Initialized data */ /*********************************/ .data szMessDebutPgm: .asciz "Program 64 bits start. \n" szCarriageReturn: .asciz "\n" szMessFinOK: .asciz "Program normal end. \n" szMessErreur: .asciz "Error !!!\n" szMessFibo: .asciz "\nFibonaci numbers :\n" .align 4 /*********************************/ /* UnInitialized data */ /*********************************/ .bss sZoneConv: .skip 24 .align 4 /*********************************/ /* code section */ /*********************************/ .text .global main main: ldr x0,qAdrszMessDebutPgm bl affichageMess // start message ldr x0,qAdrszMessFibo bl affichageMess mov x0,#0 // rank mov x1,#0 // L(0) or L(n-2) mov x2,#1 // L(1) or L(n-1) mov x3,#20 // maxi bl genererFibo ldr x0,qAdrszMessFinOK bl affichageMess b 100f 99: ldr x0,qAdrszMessErreur // error bl affichageMess mov x0, #1 // return code error b 100f 100: mov x8,EXIT svc #0 // system call qAdrszMessDebutPgm: .quad szMessDebutPgm qAdrszMessFinOK: .quad szMessFinOK qAdrszMessErreur: .quad szMessErreur qAdrsZoneConv: .quad sZoneConv qAdrszMessFibo: .quad szMessFibo /***************************************************/ /* Generation Fibonacci number */ /***************************************************/ /* x0 contains n */ /* x1 contains L(0) */ /* x2 contains L(1) */ /* x3 contains limit number */ genererFibo: stp x4,lr,[sp,-16]! stp x5,x6,[sp,-16]! mov x4,x0 cmp x3,#0 // end compute ? ble 100f cmp x0,#0 // L(0) ? bne 1f mov x0,x1 bl displayNumber add x0,x4,#1 // increment rank sub x3,x3,#1 // decrement counter bl genererFibo b 100f 1: cmp x0,#1 // L(1) ? bne 2f mov x0,x2 bl displayNumber add x0,x4,#1 sub x3,x3,#1 bl genererFibo b 100f 2: add x5,x2,x1 // add L(n-2) L(n-1) mov x0,x5 bl displayNumber add x0,x4,#1 sub x3,x3,#1 mov x1,x2 // L(n-1) -> L(n-2) mov x2,x5 // number -> L(n-1) bl genererFibo b 100f 100: ldp x5,x6,[sp],16 ldp x4,lr,[sp],16 // TODO: a completer ret /***************************************************/ /* display number */ /***************************************************/ /* x0 contains number */ displayNumber: stp x1,lr,[sp,-16]! // TODO: a completer ldr x1,qAdrsZoneConv bl conversion10 ldr x0,qAdrsZoneConv bl affichageMess ldr x0,qAdrszCarriageReturn bl affichageMess 100: ldp x1,lr,[sp],16 // TODO: a completer ret qAdrszCarriageReturn: .quad szCarriageReturn /***************************************************/ /* ROUTINES INCLUDE */ /***************************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeARM64.inc"