/* ARM assembly AARCH64 Raspberry PI 3B */ /* program varenvir64.s */ /***********************/ /* Constantes */ /***********************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64.inc" /*******************************************/ /* Macros */ /*******************************************/ //.include "../../ficmacros64.inc" @ for developer debugging /***********************/ /* Initialized data */ /***********************/ .data szMessDebutPgm: .asciz "Program 64 bits start. \n" szMessFinOK: .asciz "Program normal end. \n" szCarriageReturn: .asciz "\n" szmessresUser: .asciz "result for USER :" szmessresHome: .asciz "result for HOME :" szmessresPath: .asciz "result for PATH :" szVarRech: .asciz "USER=" .equ LGVARRECH, . - szVarRech - 1 // car zero final szVarRech1: .asciz "HOME=" .equ LGVARRECH1, . - szVarRech1 - 1 // car zero final szVarRech2: .asciz "PATH=" .equ LGVARRECH2, . - szVarRech2 - 1 // car zero final /***********************/ /* UnInitialized data */ /***********************/ .bss .align 4 /***********************/ /* code section */ /***********************/ .text .global main main: // entry of program ldr x0,qAdrszMessDebutPgm bl affichageMess mov fp,sp // fp <- start address mov x0,fp // variable search USER ldr x2,[fp] // number param add x2,x2,#2 ldr x1,qAdrszVarRech 1: ldr x0,[fp,x2,lsl #3] // load variable address cmp x0,#0 // end ? beq 2f mov x4,x0 bl searchSubBeginString // search variable name cmp x0,#-1 // no find ? cinc x2,x2,eq beq 1b ldr x0,qAdrszmessresUser bl affichageMess add x0,x4,#LGVARRECH bl affichageMess // display result ldr x0,qAdrszCarriageReturn bl affichageMess 2: ldr x2,[fp] // search variable HOME add x2,x2,#2 ldr x1,qAdrszVarRech1 3: ldr x0,[fp,x2,lsl #3] cmp x0,#0 beq 4f mov x4,x0 bl searchSubBeginString cmp x0,#-1 cinc x2,x2,eq beq 3b ldr x0,qAdrszmessresHome bl affichageMess add x0,x4,#LGVARRECH bl affichageMess ldr x0,qAdrszCarriageReturn bl affichageMess 4: ldr x2,[fp] // search variable PATH add x2,x2,#2 ldr x1,qAdrszVarRech2 5: ldr x0,[fp,x2,lsl #3] cmp x0,#0 beq 6f mov x4,x0 bl searchSubBeginString cmp x0,#-1 cinc x2,x2,eq beq 5b ldr x0,qAdrszmessresPath bl affichageMess add x0,x4,#LGVARRECH bl affichageMess ldr x0,qAdrszCarriageReturn bl affichageMess 6: ldr x0,qAdrszMessFinOK bl affichageMess 100: // standard end of the program mov x0, #0 // return code mov x8,EXIT svc 0 // perform the system call qAdrszMessDebutPgm: .quad szMessDebutPgm qAdrszMessFinOK: .quad szMessFinOK qAdrszCarriageReturn: .quad szCarriageReturn qAdrszVarRech: .quad szVarRech qAdrszVarRech1: .quad szVarRech1 qAdrszVarRech2: .quad szVarRech2 qAdrszmessresUser: .quad szmessresUser qAdrszmessresPath: .quad szmessresPath qAdrszmessresHome: .quad szmessresHome /******************************************************************/ /* search a substring at the string beguining */ /******************************************************************/ /* r0 contains the address of the input string */ /* r1 contains the address of substring */ /* r0 returns index of substring in string or -1 if not found */ searchSubBeginString: stp x1,lr,[sp,-16]! // save registers stp x2,x3,[sp,-16]! stp x4,x5,[sp,-16]! mov x2,#0 // counter byte input string mov x3,#0 // counter byte string 1: ldrb w4,[x1,x3] ldrb w5,[x0,x2] // load byte string cmp x5,#0 beq 3f cmp x4,#0 // zero final ? csel x0,xzr,x0,eq // yes string find in position 0 beq 100f cmp x5,x4 // compare character beq 2f mov x0,#-1 // no return no find b 100f 2: add x2,x2,#1 // and increment counter byte add x3,x3,#1 // and increment b 1b // and loop 3: mov x2,-1 // cmp x4,#0 mov x0,#-1 // yes returns no find bne 100f mov x0,#0 // string find in position 0 100: ldp x4,x5,[sp],16 ldp x2,x3,[sp],16 ldp x1,lr,[sp],16 // restaur registers ret /***************************************************/ /* ROUTINES INCLUDE */ /***************************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeARM64.inc"