206 lines
6.7 KiB
Plaintext
206 lines
6.7 KiB
Plaintext
/* ARM assembly AARCH64 Raspberry PI 3B */
|
|
/* program sysTime64.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
|
|
szMessEmpty: .asciz "Empty queue. \n"
|
|
szMessNotEmpty: .asciz "Not empty queue. \n"
|
|
szMessError: .asciz "Error detected !!!!. \n"
|
|
szMessResult: .asciz "GMT: @/@/@ @:@:@ @ms\n" // message result
|
|
|
|
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
|
|
/*********************************/
|
|
/* UnInitialized data */
|
|
/*********************************/
|
|
.bss
|
|
.align 4
|
|
stTVal: .skip timeval_end
|
|
stTZone: .skip timezone_end
|
|
sZoneConv: .skip 100
|
|
/*********************************/
|
|
/* code section */
|
|
/*********************************/
|
|
.text
|
|
.global main
|
|
main: // entry of program
|
|
ldr x0,qAdrstTVal // time zones
|
|
ldr x1,qAdrstTZone
|
|
mov x8,GETTIME // call system
|
|
svc 0
|
|
cmp x0,-1 // error ?
|
|
beq 99f
|
|
ldr x1,qAdrstTVal
|
|
ldr x0,[x1,timeval_sec] // timestamp in second
|
|
bl convTimeStamp
|
|
//ldr x0,qTStest1
|
|
//bl convTimeStamp
|
|
//ldr x0,qTStest2
|
|
//bl convTimeStamp
|
|
//ldr x0,qTStest3
|
|
//bl convTimeStamp
|
|
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
|
|
qAdrszMessResult: .quad szMessResult
|
|
qAdrszCarriageReturn: .quad szCarriageReturn
|
|
qTStest1: .quad 1609508339 // 01/01/2021
|
|
qTStest2: .quad 1657805939 // 14/07/2022
|
|
qTStest3: .quad 1767221999 // 31/12/2025
|
|
/******************************************************************/
|
|
/* conversion timestamp to date */
|
|
/******************************************************************/
|
|
/* x0 contains the value of timestamp */
|
|
convTimeStamp:
|
|
stp x1,lr,[sp,-16]! // save registers
|
|
ldr x2,qSecJan2020
|
|
sub x3,x0,x2 // total secondes to 01/01/2020
|
|
mov x4,60
|
|
udiv x5,x3,x4
|
|
msub x6,x5,x4,x3 // compute secondes
|
|
udiv x3,x5,x4
|
|
msub x7,x3,x4,x5 // compute minutes
|
|
mov x4,24
|
|
udiv x5,x3,x4
|
|
msub x8,x5,x4,x3 // compute hours
|
|
mov x4,(365 * 4 + 1)
|
|
udiv x9,x5,x4
|
|
lsl x9,x9,2 // multiply by 4 = year1
|
|
udiv x12,x5,x4
|
|
msub x10,x12,x4,x5
|
|
ldr x11,qAdrtbDayMonthYear
|
|
mov x12,3
|
|
mov x13,12
|
|
1:
|
|
mul x14,x13,x12
|
|
ldr x15,[x11,x14,lsl 3] // load days by year
|
|
cmp x10,x15
|
|
bge 2f
|
|
sub x12,x12,1
|
|
cmp x12,0
|
|
cbnz x12,1b
|
|
2: // x12 = year2
|
|
mov x16,11
|
|
mul x15,x13,x12
|
|
lsl x15,x15,3 // * par 8
|
|
add x14,x15,x11
|
|
3:
|
|
ldr x15,[x14,x16,lsl 3] // load days by month
|
|
cmp x10,x15
|
|
bge 4f
|
|
sub x16,x16,1
|
|
cmp x16,0
|
|
cbnz x16,3b
|
|
4: // x16 = month - 1
|
|
mul x15,x13,x12
|
|
add x15,x15,x16
|
|
ldr x1,qAdrtbDayMonthYear
|
|
ldr x3,[x1,x15,lsl 3]
|
|
sub x0,x10,x3
|
|
add x0,x0,1 // final compute day
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
ldr x0,qAdrszMessResult
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at first @ character
|
|
mov x2,x0
|
|
add x0,x16,1 // final compute month
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
mov x2,x0
|
|
add x0,x9,2020
|
|
add x0,x0,x12 // final compute year = 2020 + year1 + year2
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
mov x2,x0
|
|
mov x0,x8 // hours
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
mov x2,x0
|
|
mov x0,x7 // minutes
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
mov x2,x0
|
|
mov x0,x6 // secondes
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
mov x2,x0
|
|
ldr x1,qAdrstTVal
|
|
ldr x0,[x1,timeval_usec] // millisecondes
|
|
ldr x1,qAdrsZoneConv
|
|
bl conversion10
|
|
mov x0,x2
|
|
ldr x1,qAdrsZoneConv
|
|
bl strInsertAtCharInc // insert result at next @ character
|
|
bl affichageMess
|
|
b 100f
|
|
99:
|
|
ldr x0,qAdrszMessError
|
|
bl affichageMess
|
|
100:
|
|
ldp x1,lr,[sp],16 // restaur 2 registers
|
|
ret // return to address lr x30
|
|
qAdrsZoneConv: .quad sZoneConv
|
|
qSecJan2020: .quad 1577836800
|
|
qAdrtbDayMonthYear: .quad tbDayMonthYear
|
|
/********************************************************/
|
|
/* File Include fonctions */
|
|
/********************************************************/
|
|
/* for this file see task include a file in language AArch64 assembly */
|
|
.include "../includeARM64.inc"
|