/* ARM assembly AARCH64 Raspberry PI 3B */ /* program repeatstring.s */ /*******************************************/ /* Constantes */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64.inc" .equ BUFFERSIZE, 2000 /*******************************************/ /* Macros */ /*******************************************/ //.include "../../ficmacros64.inc" // for developer debugging /*********************************/ /* Initialized data */ /*********************************/ .data szMessDebutPgm: .asciz "Program 64 bits start. \n" szCarriageReturn: .asciz "\n" szMessFinOK: .asciz "Program normal end. \n" szMessErreur: .asciz "Error Buffer too small!!!\n" szString1: .asciz "ho" /*********************************/ /* UnInitialized data */ /*********************************/ .bss .align 4 sZoneConv: .skip 24 sBuffer: .skip BUFFERSIZE /*********************************/ /* code section */ /*********************************/ .text .global main main: ldr x0,qAdrszMessDebutPgm bl affichageMess // start message ldr x0,qAdrszString1 // load phrase adress ldr x1,qAdrsBuffer mov x2,#5 bl repeatString cmp x0,#0 ble 99f ldr x0,qAdrsBuffer // buffer display bl affichageMess ldr x0,qAdrszCarriageReturn bl affichageMess 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 qAdrszString1: .quad szString1 qAdrsBuffer: .quad sBuffer qAdrsZoneConv: .quad sZoneConv qAdrszCarriageReturn: .quad szCarriageReturn /******************************************************************/ /* test if number is aritmetic number */ /******************************************************************/ /* x0 contains string address */ /* x1 contains buffer address */ /* x2 number repeat */ /* x0 return buffer writed length or -1 if error*/ repeatString: stp x3,lr,[sp,-16]! // save registers stp x4,x5,[sp,-16]! // save registers stp x6,x7,[sp,-16]! // save registers mov x3,#0 // indice repeat mov x4,#0 // indice buffer 1: mov x5,#0 // indice string 2: ldrb w6,[x0,x5] // load string characters cmp x6,#0 // end string ? beq 3f strb w6,[x1,x4] // store char in buffer add x4,x4,#1 // increment indice add x5,x5,#1 b 2b // and loop 3: mul x6,x5,x2 // compute repeat length string cmp x6,#BUFFERSIZE // compare to buffer length bge 99f // error ? add x3,x3,#1 // increment repeat counter cmp x3,x2 // end ? blt 1b mov x6,#0 strb w6,[x1,x4] // final zero mov x0,x4 // return length b 100f 99: mov x0,#-1 // error 100: ldp x6,x7,[sp],16 // restaur r egisters ldp x4,x5,[sp],16 // restaur registers ldp x3,lr,[sp],16 // restaur registers ret /***************************************************/ /* ROUTINES INCLUDE */ /***************************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeARM64.inc"