System time: Difference between revisions
Content added Content deleted
(add task to ARM64 assembly Raspberry Pi) |
(Add task to ARM assembly Raspberry pi) |
||
Line 244: | Line 244: | ||
Sunday, August 14, 2011 10:43:57 PM |
Sunday, August 14, 2011 10:43:57 PM |
||
</pre> |
</pre> |
||
=={{header|ARM Assembly}}== |
|||
{{works with|as|Raspberry Pi}} |
|||
<lang ARM Assembly> |
|||
/* ARM assembly Raspberry PI */ |
|||
/* program sysTime.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 */ |
|||
/*******************************************/ |
|||
/* Constantes */ |
|||
/*******************************************/ |
|||
.equ STDOUT, 1 @ Linux output console |
|||
.equ EXIT, 1 @ Linux syscall |
|||
.equ WRITE, 4 @ Linux syscall |
|||
.equ BRK, 0x2d @ Linux syscall |
|||
.equ CHARPOS, '@' |
|||
.equ GETTIME, 0x4e @ call system linux gettimeofday |
|||
/*******************************************/ |
|||
/* Structures */ |
|||
/********************************************/ |
|||
/* example structure time */ |
|||
.struct 0 |
|||
timeval_sec: @ |
|||
.struct timeval_sec + 4 |
|||
timeval_usec: @ |
|||
.struct timeval_usec + 4 |
|||
timeval_end: |
|||
.struct 0 |
|||
timezone_min: @ |
|||
.struct timezone_min + 4 |
|||
timezone_dsttime: @ |
|||
.struct timezone_dsttime + 4 |
|||
timezone_end: |
|||
/*********************************/ |
|||
/* Initialized data */ |
|||
/*********************************/ |
|||
.data |
|||
szMessError: .asciz "Error detected !!!!. \n" |
|||
szMessResult: .asciz "GMT: @/@/@ @:@:@ @ms\n" @ message result |
|||
szCarriageReturn: .asciz "\n" |
|||
.align 4 |
|||
tbDayMonthYear: .int 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 |
|||
.int 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700 |
|||
.int 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065 |
|||
.int 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 r0,iAdrstTVal |
|||
ldr r1,iAdrstTZone |
|||
mov r7,#GETTIME |
|||
svc 0 |
|||
cmp r0,#-1 @ error ? |
|||
beq 99f |
|||
ldr r0,iAdrstTVal |
|||
ldr r1,[r0,#timeval_sec] @ timestemp in second |
|||
ldr r2,iSecJan2020 |
|||
sub r0,r1,r2 @ total secondes to 01/01/2020 |
|||
mov r1,#60 |
|||
bl division |
|||
mov r0,r2 |
|||
mov r6,r3 @ compute secondes |
|||
mov r1,#60 |
|||
bl division |
|||
mov r7,r3 @ compute minutes |
|||
mov r0,r2 |
|||
mov r1,#24 |
|||
bl division |
|||
mov r8,r3 @ compute hours |
|||
mov r0,r2 |
|||
mov r11,r0 |
|||
mov r1,#(365 * 4 + 1)/4 |
|||
bl division |
|||
lsl r9,r2,#2 @ multiply by 4 = year1 |
|||
mul r10,r9,r1 |
|||
sub r10,r11,r10 |
|||
ldr r1,iAdrtbDayMonthYear |
|||
mov r2,#3 |
|||
mov r3,#12 |
|||
1: |
|||
mul r11,r3,r2 |
|||
ldr r12,[r1,r11,lsl #2] @ load days by year |
|||
cmp r10,r12 |
|||
bge 2f |
|||
sub r2,r2,#1 |
|||
cmp r2,#0 |
|||
bne 1b |
|||
2: @ r2 = year2 |
|||
mov r5,#11 |
|||
mul r4,r3,r2 |
|||
add r4,r1 |
|||
3: |
|||
ldr r12,[r4,r5,lsl #2] @ load days by month |
|||
cmp r10,r12 |
|||
bge 4f |
|||
subs r5,r5,#1 |
|||
bne 3b |
|||
4: @ r5 = month - 1 |
|||
sub r0,r10,r12 |
|||
add r0,r0,#1 @ final compute day |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 @ this function do not zero final |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
ldr r0,iAdrszMessResult |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at first @ character |
|||
mov r3,r0 |
|||
add r0,r5,#1 @ final compute month |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
mov r3,r0 |
|||
ldr r11,iYearStart |
|||
add r0,r9,r11 |
|||
add r0,r0,r2 @ final compute year = 2020 + year1 + year2 |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
mov r3,r0 |
|||
mov r0,r8 @ hours |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
mov r3,r0 |
|||
mov r0,r7 @ minutes |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
mov r3,r0 |
|||
mov r0,r6 @ secondes |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
mov r3,r0 |
|||
ldr r1,iAdrstTVal |
|||
ldr r0,[r1,#timeval_usec] @ millisecondes |
|||
ldr r1,iAdrsZoneConv |
|||
bl conversion10 |
|||
mov r4,#0 @ store zero final |
|||
strb r4,[r1,r0] |
|||
mov r0,r3 |
|||
ldr r1,iAdrsZoneConv |
|||
bl strInsertAtCharInc @ insert result at next @ character |
|||
bl affichageMess |
|||
b 100f |
|||
99: |
|||
ldr r0,iAdrszMessError |
|||
bl affichageMess |
|||
100: @ standard end of the program |
|||
mov r0,#0 @ return code |
|||
mov r7,#EXIT @ request to exit program |
|||
svc 0 @ perform the system call |
|||
iAdrszMessError: .int szMessError |
|||
iAdrstTVal: .int stTVal |
|||
iAdrstTZone: .int stTZone |
|||
iAdrszMessResult: .int szMessResult |
|||
iAdrszCarriageReturn: .int szCarriageReturn |
|||
iAdrsZoneConv: .int sZoneConv |
|||
iSecJan2020: .int 1577836800 |
|||
iAdrtbDayMonthYear: .int tbDayMonthYear |
|||
iYearStart: .int 2020 |
|||
/***************************************************/ |
|||
/* ROUTINES INCLUDE */ |
|||
/***************************************************/ |
|||
.include "../affichage.inc" |
|||
</lang> |
|||
{{Output}} |
|||
<pre> |
|||
GMT: 29/3/2020 18:39:13 717877ms |
|||
</pre> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||