Preprocessor compiler date

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

Preprocessor compiler date

Jump to solution
2,267 Views
IlConte
Contributor IV

Dear. I use S08JM16 with assembler code warrior compiler.

There is a preprocessor directive for compiler date/time to use in my code; like __DATE__ and __TIME__ for c preprocessor ?

 

Thanks

 

Stefano

Labels (1)
0 Kudos
Reply
1 Solution
1,738 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

No . it's not for assembly .

View solution in original post

0 Kudos
Reply
12 Replies
1,738 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

YES, CodeWarrior supports those C preprocessor (__DATE__ and __TIME__).

below is the compiler predefied macros by Codewarrior

__LINE__

   

Line number in the current source file

__FILE__

   

Name of the source file where it appears

__DATE__

   

The date of compilation as a string

__TIME__

   

The time of compilation as a string

__STDC__

   

Set to 1 if the -Ansi: Strict ANSI compiler option has been given. Otherwise, additional keywords are accepted (not in the ANSI standard).

for more information, please check compiler manual under CW install folder

0 Kudos
Reply
1,738 Views
IlConte
Contributor IV

For c language OK.

I need to know if is possible also for assembler language, like this :

dc.b __DATE__
0 Kudos
Reply
1,739 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

No . it's not for assembly .

0 Kudos
Reply
1,738 Views
IlConte
Contributor IV

In assembler how can I have the compiler date and time ? Is possible ?

Thanks

0 Kudos
Reply
1,738 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

I don't think it;s possiable in pure assembly program, i normally implement in mix assembly and C. define the TIME to a global variable in C file. then call this variable from  from assembly file

0 Kudos
Reply
1,738 Views
IlConte
Contributor IV

Solved the problem using a vbs script executed in Pre-Build-Step command

Thanks all

0 Kudos
Reply
1,738 Views
AndyUK
Contributor I

Hi,

I know this thread is a couple of years old - but I'm wondering if I can get an answer as to how you did this ?

I'm trying to insert a time / date stamp into my code, and I can't get it to work.

It sounds like such a simple task, but I'm stuck !

Any chance you could explain how you achieved this ?

Thanks

0 Kudos
Reply
1,738 Views
tonyp
Senior Contributor II

You don't mention if you're interested in ASM or C.

For example with my assembler (ASM8) it would be as simple as inserting something like this:

  fcc '{:year}-{:month(z)}-{:date(z)} {:hour(z)}:{:min(z)}:{:sec(z)}'

where you want your date/time stamp to appear.

If you happen to use CW, I don't know much about it, however you could use a simple generic script like this Lua one to create the needed include file, and make it part of your make process:

--------------- cut here ---------------

io.open('today.inc','w'):write(os.date(' fcc \'%Y-%m-%d %H:%M:%S\'')):close()

--------------- cut here ---------------

This is for asm use, change it accordingly for C.

Hope this helps.

0 Kudos
Reply
1,738 Views
AndyUK
Contributor I

Sorry - I'm using Assembler - the built in version that comes with CW.

I tried using the solution you use with ASM8, but CW just inserts the literal string " {:year}-{:month(z)}-{:date(z)} {:hour(z)}:{:min(z)}:{:sec(z)} " into the code, not the actual date / time.

I don't understand your second suggestion - any chance you could expand on it ?

Thanks

0 Kudos
Reply
1,738 Views
tonyp
Senior Contributor II

The string was meant to be used with ASM8 but not with CW.  Obviously it won't work with CW.

The 2nd suggestion is to use a generic script language to do this work for you as part of the build process, i.e., one extra step in your makefile.  (If you don't use makefiles then simply run it right before you assemble your code whichever way you normally do.)

I choose Lua for these tasks as it is one such script language which combines programming simplicity and sophistication, in my view -- but you could use whatever other scripting language you're comfortable with assuming it provides some method to get the system clock as a string.

So, the script I gave in the earlier reply is for Lua.  Assuming lua.exe is somewhere in your path (no installation needed, just place the lua.exe somewhere in your path), and you have named the script 'generate_datetime.lua' you would have to give this command (preferably from the console):

lua generate_datetime.lua

This should create the file today.inc (in my example) in the same directory you were when you ran the above command.  So, you probably want to run it from inside the project's directory.

The produced file will contain the needed assembly language code that will embed the date/time stamp in your app.

Every time the script is run the file will be updated with the current date/time stamp.  Then just assemble your program as usual.

To have the date/time stamp appear in your code, at the relevant point in your source you have to include the generated file, like so:

#include today.inc

Simple?

0 Kudos
Reply
1,738 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome

0 Kudos
Reply
1,738 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

YES, CodeWarrior supports those C preprocessor (__DATE__ and __TIME__).

below is the compiler predefied macros by Codewarrior

__LINE__

Line number in the current source file

__FILE__

Name of the source file where it appears

__DATE__

The date of compilation as a string

__TIME__

The time of compilation as a string

__STDC__

Set to 1 if the -Ansi: Strict ANSI compiler option has been given. Otherwise, additional keywords are accepted (not in the ANSI standard).

for more information, please check compiler manual under CW install folder

0 Kudos
Reply