__DATE__ and __TIME__ in assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

__DATE__ and __TIME__ in assembly

4,133 Views
SVC2
Contributor II

Hi,

Is there a way to insert date and time in an assembly code (equivalent to __DATE__ and __TIME__ in C).

Woul like to have something like:

 

Code:
 .global _aDate .global _aTime    .data _aDate: .long __DATE__  ; assembler MACRO_aTime: .long __TIME__  ; assembler MACRO .end


Thanks,


Labels (1)
0 Kudos
Reply
6 Replies

566 Views
CrasyCat
Specialist III
Hello
 
Please do not do cross posting.
As explained in thread
Macro-assembler language does not support predefined symbols like an ANSI C or C++ compiler does.
 
Which assembler are you using? CodeWarrior?
There is no __DATE__ macro to retrieve assembling date in the CodeWarrior macro assembler.
 
CrasyCat
0 Kudos
Reply

566 Views
SVC2
Contributor II
Sorry about the cross posting. I didn't know which forum was best suited to my query.
 
I am using CodeWarrior Assembler.
 
S.
 
0 Kudos
Reply

566 Views
Lundin
Senior Contributor IV
This is from one CW project of mine and should work:

/* h file */
#ifndef _LINKING_DAY_H
#define _LINKING_DAY_H

#pragma CONST_SEG MY_DATE

extern const char LinkingDay[];
extern const char LinkingTime[];

#pragma CONST_SEG DEFAULT

#endif /* _LINKING_DAY_H */


/* c file */
#include < time.h>
#include "LinkingDay.h"


#pragma CONST_SEG MY_DATE

const char LinkingDay[] = __DATE__;
const char LinkingTime[] = __TIME__;

#pragma CONST_SEG DEFAULT


 ; asm file
xref LinkingDay
xref LinkingTime
0 Kudos
Reply

566 Views
SVC2
Contributor II
Thanks for the hint.
 
I tried the code and was wondering what the pragmas are for? My compiler (CW7.0) is complaining:
 
Code:
Warning : illegal #pragmadate&Time.h line 20   #pragma CONST_SEG MY_DATE 

 
Also, xref is an Undefined macro or opcode. Instead I tried:
Code:
DATE   .long _LinkingDayTIME:   .long _LinkingTime

 
which compiled.
 
Now how do I interpret the result? The code is converting an array of 11 character (_LinkingDay) or 8 characters (_LinkingTime) to a long.
 
Is this what I was supposed to do or I missed something?
 
Thanks,
Simon
 
0 Kudos
Reply

566 Views
Lundin
Senior Contributor IV
The pragma is there to allocate the variables at a specific location in memory (Code.
You need to have that segment in the .prm file of your CW project in order to get it working.

Still, if you couldn't xref them, you could always access that address to get the strings. If the compiler doesn't realize that the variables are used and optimize them away, you can add the variable names in the .prm file under ENTRIES:

ENTRIES
LinkingDay
LinkingTime
END

Whatever you do with the strings in assembler is up to you. They will have the format "Aug 28 2008" and "09:00:00" respectively.
0 Kudos
Reply

566 Views
CrasyCat
Specialist III
Hello SVC2
 
Note that the pragma and ENTRIES command Ludin is speaking about is valid if you are building code on HC08 or HC12 MCU.
 
This cannot be used for other microcontrollers.
 
CrasyCat
0 Kudos
Reply