/* ARM assembly Raspberry PI or android with termux */ /* program filelen.s */ /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a file in arm assembly */ /************************************/ /* Constantes */ /************************************/ .include "../constantes.inc" .equ OPEN, 5 .equ NEWFSTAT, 0xc5 .equ O_RDWR, 0x0002 @ open for reading and writing /************************************/ /* structure de type stat : file infos */ /************************************/ .struct 0 Stat_dev_t: /* ID of device containing file */ .struct Stat_dev_t + 8 Stat_ino_t: /* inode */ .struct Stat_ino_t + 8 Stat_mode_t: /* File type and mode */ .struct Stat_mode_t + 4 Stat_nlink_t: /* Number of hard links */ .struct Stat_nlink_t + 4 Stat_uid_t: /* User ID of owner */ .struct Stat_uid_t + 4 Stat_gid_t: /* Group ID of owner */ .struct Stat_gid_t + 4 Stat_rdev_t: /* Device ID (if special file) */ .struct Stat_rdev_t + 8 Stat_size_deb: /* la taille est sur 8 octets si gros fichiers */ .struct Stat_size_deb + 8 Stat_size_t: /* Total size, in bytes */ .struct Stat_size_t + 4 Stat_blksize_t: /* Block size for filesystem I/O */ .struct Stat_blksize_t + 4 Stat_blkcnt_t: /* Number of 512B blocks allocated */ .struct Stat_blkcnt_t + 4 Stat_atime: /* date et heure fichier */ .struct Stat_atime + 8 Stat_mtime: /* date et heure modif fichier */ .struct Stat_atime + 8 Stat_ctime: /* date et heure creation fichier */ .struct Stat_atime + 8 Stat_End: /*********************************/ /* Initialized data */ /*********************************/ .data szMessResult: .asciz " File size = " szCarriageReturn: .asciz "\n" szMessErrOpen: .asciz "Error open file\n" szMessErrStat: .asciz "Error stats file\n" szFileName: .asciz "input.txt" szFileName1: .asciz "../../../input.txt" .align 2 /*********************************/ /* UnInitialized data */ /*********************************/ .bss sZoneConv: .skip 24 sBuffer: .skip Stat_End /*********************************/ /* code section */ /*********************************/ .text .global main main: ldr r0,iAdrszFileName @ file name bl filesize cmp r0,#0 blt 100f ldr r1,iAdrsZoneConv bl conversion10 @ call décimal conversion mov r0,#4 ldr r1,iAdrszFileName ldr r2,iAdrszMessResult ldr r3,iAdrsZoneConv @ insert conversion in message ldr r4,iAdrszCarriageReturn push {r4} bl displayStrings @ display message add sp,#4 @ 1 parameter on stack ldr r0,iAdrszFileName1 @ file name bl filesize cmp r0,#0 blt 100f ldr r1,iAdrsZoneConv bl conversion10 @ call décimal conversion mov r0,#4 ldr r1,iAdrszFileName1 ldr r2,iAdrszMessResult ldr r3,iAdrsZoneConv @ insert conversion in message ldr r4,iAdrszCarriageReturn push {r4} bl displayStrings @ display message add sp,#4 @ 1 parameter on stack 100: @ standard end of the program mov r0, #0 @ return code mov r7, #EXIT @ request to exit program svc #0 @ perform the system call iAdrszCarriageReturn: .int szCarriageReturn iAdrsZoneConv: .int sZoneConv iAdrszMessResult: .int szMessResult iAdrszFileName: .int szFileName iAdrszFileName1: .int szFileName1 iAdrsBuffer: .int sBuffer iAdrszMessErrOpen: .int szMessErrOpen iAdrszMessErrStat: .int szMessErrStat /***************************************************/ /* display multi strings */ /***************************************************/ /* r0 contains number strings address */ filesize: @ INFO: filesize push {r1-r8,fp,lr} @ save des registres mov r1,#O_RDWR @ flags mov r2,#0 @ mode mov r7,#OPEN svc 0 cmp r0,#0 @ error ? ble 99f mov r8,r0 @ Fd save ldr r1,iAdrsBuffer @ buffer address mov r7,#NEWFSTAT svc 0 cmp r0,#0 blt 98f ldr r0,iAdrsBuffer ldr r1,iAdrsBuffer @ buffer address ldr r4,[r1,#Stat_size_t] @ file size mov r0,r8 mov r7,#CLOSE mov r0,r4 @ return size b 100f 98: ldr r0,iAdrszMessErrStat bl affichageMess mov r0,#-1 b 100f 99: ldr r0,iAdrszMessErrOpen bl affichageMess mov r0,#-1 100: pop {r1-r8,fp,pc} /***************************************************/ /* display multi strings */ /***************************************************/ /* r0 contains number strings address */ /* r1 address string1 */ /* r2 address string2 */ /* r3 address string3 */ /* other address on the stack */ /* thinck to add number other address * 4 to add to the stack */ displayStrings: @ INFO: displayStrings push {r1-r4,fp,lr} @ save des registres add fp,sp,#24 @ save paraméters address (6 registers saved * 4 bytes) mov r4,r0 @ save strings number cmp r4,#0 @ 0 string -> end ble 100f mov r0,r1 @ string 1 bl affichageMess cmp r4,#1 @ number > 1 ble 100f mov r0,r2 bl affichageMess cmp r4,#2 ble 100f mov r0,r3 bl affichageMess cmp r4,#3 ble 100f mov r3,#3 sub r2,r4,#4 1: @ loop extract address string on stack ldr r0,[fp,r2,lsl #2] bl affichageMess subs r2,#1 bge 1b 100: pop {r1-r4,fp,pc} /***************************************************/ /* ROUTINES INCLUDE */ /***************************************************/ .include "../affichage.inc"