/* ARM assembly AARCH64 Raspberry PI 3B */ /* program dateFormat64.s */ /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64.inc" .equ GETTIME, 169 // call system linux gettimeofday /*******************************************/ /* Structures */ /********************************************/ /* example structure time */ .struct 0 timeval_sec: // .struct timeval_sec + 8 timeval_usec: // .struct timeval_usec + 8 timeval_end: .struct 0 timezone_min: // .struct timezone_min + 8 timezone_dsttime: // .struct timezone_dsttime + 8 timezone_end: /*********************************/ /* Initialized data */ /*********************************/ .data szMessError: .asciz "Error detected !!!!. \n" szMessResult: .asciz "Date : @/@/@ \n" // message result szMessResult1: .asciz "Date day : @ @ @ @ \n" // message result szJan: .asciz "Janvier" szFev: .asciz "Fèvrier" szMars: .asciz "Mars" szAvril: .asciz "Avril" szMai: .asciz "Mai" szJuin: .asciz "Juin" szJuil: .asciz "Juillet" szAout: .asciz "Aout" szSept: .asciz "Septembre" szOct: .asciz "Octobre" szNov: .asciz "Novembre" szDec: .asciz "Décembre" szLundi: .asciz "Lundi" szMardi: .asciz "Mardi" szMercredi: .asciz "Mercredi" szJeudi: .asciz "Jeudi" szVendredi: .asciz "Vendredi" szSamedi: .asciz "Samedi" szDimanche: .asciz "Dimanche" szCarriageReturn: .asciz "\n" .align 4 tbDayMonthYear: .quad 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 .quad 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700 .quad 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065 .quad 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430 tbMonthName: .quad szJan .quad szFev .quad szMars .quad szAvril .quad szMai .quad szJuin .quad szJuil .quad szAout .quad szSept .quad szOct .quad szNov .quad szDec tbDayName: .quad szLundi .quad szMardi .quad szMercredi .quad szJeudi .quad szVendredi .quad szSamedi .quad szDimanche /*********************************/ /* UnInitialized data */ /*********************************/ .bss .align 4 stTVal: .skip timeval_end stTZone: .skip timezone_end sZoneConv: .skip 24 /*********************************/ /* code section */ /*********************************/ .text .global main main: // entry of program ldr x0,qAdrstTVal ldr x1,qAdrstTZone mov x8,#GETTIME svc 0 cmp x0,#-1 // error ? beq 99f ldr x1,qAdrstTVal ldr x0,[x1,#timeval_sec] // timestamp in second bl dateFormatNum ldr x0,[x1,#timeval_sec] // timestamp in second bl dateFormatAlpha ldr x0,qTStest1 bl dateFormatNum ldr x0,qTStest1 bl dateFormatAlpha ldr x0,qTStest2 bl dateFormatNum ldr x0,qTStest2 bl dateFormatAlpha ldr x0,qTStest3 bl dateFormatNum ldr x0,qTStest3 bl dateFormatAlpha b 100f 99: ldr x0,qAdrszMessError 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 qAdrszMessError: .quad szMessError qAdrstTVal: .quad stTVal qAdrstTZone: .quad stTZone qAdrszCarriageReturn: .quad szCarriageReturn qAdrsZoneConv: .quad sZoneConv qTStest1: .quad 1609508339 // 01/01/2021 qTStest2: .quad 1657805939 // 14/07/2022 qTStest3: .quad 1767221999 // 31/12/2025 /******************************************************************/ /* date format numeric */ /******************************************************************/ /* x0 contains the timestamp in seconds */ dateFormatNum: stp x1,lr,[sp,-16]! // save registers ldr x2,qSecJan2020 sub x0,x0,x2 // total secondes to 01/01/2020 mov x1,60 udiv x0,x0,x1 // divide secondes udiv x0,x0,x1 // divide minutes mov x1,#24 udiv x0,x0,x1 // divide hours mov x11,x0 mov x1,#(365 * 4 + 1) udiv x9,x0,x1 lsl x9,x9,#2 // multiply by 4 = year1 mov x1,#(365 * 4 + 1) udiv x2,x11,x1 msub x10,x2,x1,x11 ldr x1,qAdrtbDayMonthYear mov x2,#3 mov x3,#12 1: mul x11,x3,x2 ldr x4,[x1,x11,lsl 3] // load days by year cmp x10,x4 bge 2f sub x2,x2,1 cbnz x2,1b 2: // x2 = year2 mov x5,11 mul x11,x3,x2 lsl x11,x11,3 add x11,x11,x1 // table address 3: ldr x4,[x11,x5,lsl 3] // load days by month cmp x10,x4 bge 4f subs x5,x5,1 bne 3b 4: // x5 = month - 1 mul x11,x3,x2 add x11,x11,x5 ldr x1,qAdrtbDayMonthYear ldr x3,[x1,x11,lsl 3] sub x0,x10,x3 add x0,x0,1 // final compute day ldr x1,qAdrsZoneConv bl conversion10 // this function do not zero final ldr x0,qAdrszMessResult ldr x1,qAdrsZoneConv bl strInsertAtCharInc // insert result at first // character mov x3,x0 add x0,x5,1 // final compute month cmp x0,12 sub x1,x0,12 csel x0,x1,x0,gt ldr x1,qAdrsZoneConv bl conversion10 mov x0,x3 ldr x1,qAdrsZoneConv bl strInsertAtCharInc // insert result at next // character mov x3,x0 ldr x11,qYearStart add x0,x9,x11 add x0,x0,x2 // final compute year = 2020 + yeax1 + yeax2 ldr x1,qAdrsZoneConv bl conversion10 mov x0,x3 ldr x1,qAdrsZoneConv bl strInsertAtCharInc // insert result at next // character bl affichageMess 100: ldp x1,lr,[sp],16 // restaur 2 registers ret // return to address lr x30 qAdrszMessResult: .quad szMessResult /******************************************************************/ /* date format alphanumeric */ /******************************************************************/ /* x0 contains the timestamp in seconds */ dateFormatAlpha: stp x1,lr,[sp,-16]! // save registers ldr x2,qSecJan2020 sub x0,x0,x2 // total secondes to 01/01/2020 mov x6,x0 mov x1,60 udiv x0,x0,x1 udiv x0,x0,x1 mov x1,24 udiv x0,x0,x1 mov x7,x0 mov x1,(365 * 4 + 1) udiv x9,x0,x1 lsl x9,x9,#2 // multiply by 4 = year1 mov x1,(365 * 4 + 1) udiv x0,x7,x1 msub x10,x0,x1,x7 ldr x1,qAdrtbDayMonthYear mov x8,3 mov x3,12 1: mul x7,x3,x8 ldr x4,[x1,x7,lsl 3] // load days by year cmp x10,x4 bge 2f sub x8,x8,1 cmp x8,0 bne 1b 2: // x8 = yeax2 mov x5,#11 mul x7,x3,x8 lsl x7,x7,3 add x7,x7,x1 3: ldr x4,[x7,x5,lsl 3] // load days by month cmp x10,x4 bge 4f subs x5,x5,1 bne 3b 4: // x5 = month - 1 mov x0,x6 // number secondes depuis 01/01/2020 ldr x1,qNbSecByDay udiv x0,x6,x1 mov x1,7 udiv x2,x0,x1 msub x3,x2,x1,x0 add x2,x3,2 cmp x2,7 sub x3,x2,7 csel x2,x3,x2,ge ldr x1,qAdrtbDayName ldr x1,[x1,x2,lsl 3] ldr x0,qAdrszMessResult1 bl strInsertAtCharInc // insert result at next // character mov x3,x0 mov x7,12 mul x11,x7,x8 add x11,x11,x5 ldr x1,qAdrtbDayMonthYear ldr x7,[x1,x11,lsl 3] sub x0,x10,x7 add x0,x0,1 // final compute day ldr x1,qAdrsZoneConv bl conversion10 // this function do not zero final mov x0,x3 ldr x1,qAdrsZoneConv bl strInsertAtCharInc // insert result at first // character mov x3,x0 ldr x1,qAdrtbMonthName cmp x5,12 sub x2,x5,12 csel x5,x2,x5,ge ldr x1,[x1,x5,lsl 3] // month name mov x0,x3 bl strInsertAtCharInc // insert result at first // character mov x3,x0 ldr x0,qYearStart add x0,x0,x8 add x0,x0,x9 // final compute year = 2020 + yeax1 + yeax2 ldr x1,qAdrsZoneConv bl conversion10 // this function do not zero final mov x0,x3 ldr x1,qAdrsZoneConv bl strInsertAtCharInc // insert result at first // character bl affichageMess 100: ldp x1,lr,[sp],16 // restaur 2 registers ret // return to address lr x30 qAdrszMessResult1: .quad szMessResult1 qSecJan2020: .quad 1577836800 qAdrtbDayMonthYear: .quad tbDayMonthYear qYearStart: .quad 2020 qAdrtbMonthName: .quad tbMonthName qAdrtbDayName: .quad tbDayName qNbSecByDay: .quad 3600 * 24 /********************************************************/ /* File Include fonctions */ /********************************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeARM64.inc"