Task

Verify that a file called     input.txt     and   a directory called     docs     exist.



This should be done twice:  

   once for the current working directory,   and
   once for a file and a directory in the filesystem root.


Optional criteria (May 2015):   verify it works with:

   zero-length files
   an unusual filename:     `Abdu'l-Bahá.txt  


 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program verifFic64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ CHDIR,   49
.equ AT_FDCWD,    -100
 
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessFound1:     .asciz "File 1 found.\n"
szMessFound2:     .asciz "File 2 found.\n"
szMessNotFound1:  .asciz "File 1 not found.\n"
szMessNotFound2:  .asciz "File 2 not found.\n"
szMessDir2:       .asciz "File 2 is a directory.\n"
szMessNotAuth2:   .asciz "File 2 permission denied.\n"
szCarriageReturn: .asciz "\n"
 
/* areas strings  */
szPath2:          .asciz "/"
szFicName1:       .asciz "test1.txt"
szFicName2:       .asciz "root"
 
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss 
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main:                        // entry of program
 
    /*************************************
     open file 1
    ************************************/
    mov x0,AT_FDCWD          // current directory
    ldr x1,qAdrszFicName1    // file name
    mov x2,#O_RDWR           // flags
    mov x3,#0                // mode 
    mov x8, #OPEN            // call system OPEN 
    svc 0 
    cmp x0,#0                // error ?
    ble 1f
    mov x1,x0                // FD
    ldr x0,qAdrszMessFound1
    bl affichageMess
                             // close file
    mov x0,x1                // Fd 
    mov x8, #CLOSE 
    svc 0 
    b 2f
1:
    ldr x0,qAdrszMessNotFound1
    bl affichageMess
2:
    /*************************************
     open file 2
    ************************************/
    ldr x0,qAdrszPath2
    mov x8,CHDIR            // call system change directory
    svc 0 
    mov x0,AT_FDCWD         // current directory
    ldr x1,qAdrszFicName2   // file name 
    mov x2,O_RDWR           //  flags
    mov x3,0                // mode 
    mov x8,OPEN             // call system OPEN 
    svc 0 
    cmp x0,-21              // is a directory ?
    beq 4f
    cmp x0,0                // error ? 
    ble 3f
    mov x1,x0               // FD
    ldr x0,qAdrszMessFound2
    bl affichageMess
                            // close file
    mov x0,x1               // Fd 
    mov x8, #CLOSE 
    svc 0 
    b 100f
3:
    ldr x0,qAdrszMessNotFound2
    bl affichageMess
    b 100f
4:
    ldr x0,qAdrszMessDir2
    bl affichageMess
100:                           // standard end of the program
    mov x0,0                   // return code
    mov x8,EXIT                // request to exit program
    svc 0                      // perform the system call
qAdrszFicName1:            .quad szFicName1
qAdrszFicName2:            .quad szFicName2
qAdrszMessFound1:          .quad szMessFound1
qAdrszMessFound2:          .quad szMessFound2
qAdrszMessNotFound1:       .quad szMessNotFound1
qAdrszMessNotFound2:       .quad szMessNotFound2
qAdrszMessNotAuth2:        .quad szMessNotAuth2
qAdrszPath2:               .quad szPath2
qAdrszMessDir2:            .quad szMessDir2
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 