Task

(Over)write a file so that it contains a string.



The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program writeFile64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
szMessErreur:  .asciz "Error open file.\n"
szMessErreur1: .asciz "Error close file.\n"
szMessErreur2: .asciz "Error write file.\n"
szMessWriteOK: .asciz "String write in file OK.\n"
 
szParamNom:    .asciz "./fic1.txt"      // file name
sZoneEcrit:    .ascii "(Over)write a file so that it contains a string."
               .equ LGZONEECRIT, . - sZoneEcrit
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
 
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                         // entry of program 
                              // file open
    mov x0,AT_FDCWD           // current directory
    ldr x1,qAdrszParamNom     // filename
    mov x2,O_CREAT|O_WRONLY   //  flags
    ldr x3,oficmask1          // mode
    mov x8,OPEN               // Linux call system
    svc 0                     //
    cmp x0,0                  // error ?
    ble erreur                // yes
    mov x28,x0                // save File Descriptor
                              // x0 = FD
    ldr x1,qAdrsZoneEcrit     // write string address
    mov x2,LGZONEECRIT        // string size
    mov x8,WRITE              // Linux call system
    svc 0 
    cmp x0,0                 // error ?
    ble erreur2               // yes
                              // close file
    mov x0,x28                // File Descriptor
    mov x8,CLOSE              // Linuc call system
    svc 0 
    cmp x0,0                  // error ?
    blt erreur1
    ldr x0,qAdrszMessWriteOK
    bl affichageMess 
    mov x0,#0                 // return code OK
    b 100f
erreur:    
    ldr x1,qAdrszMessErreur
    bl affichageMess          // display error message
    mov x0,#1
    b 100f
erreur1:    
    ldr x1,qAdrszMessErreur1  // x0 <- adresse chaine 
    bl affichageMess          // display error message
    mov x0,#1                 // return code error
    b 100f    
erreur2:    
    ldr x0,qAdrszMessErreur2
    bl affichageMess          // display error message
    mov x0,#1                 // return code error
    b 100f
100:                          // program end
    mov x8,EXIT
    svc #0
qAdrszParamNom:            .quad szParamNom
qAdrszMessErreur:          .quad szMessErreur
qAdrszMessErreur1:         .quad szMessErreur1
qAdrszMessErreur2:         .quad szMessErreur2
qAdrszMessWriteOK:         .quad szMessWriteOK
qAdrsZoneEcrit:            .quad sZoneEcrit
oficmask1:                 .quad 0644         // this zone is Octal number (0 before) 
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
 