Preprocessor compiler date

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Preprocessor compiler date

跳至解决方案
3,556 次查看
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

标签 (1)
0 项奖励
回复
1 解答
3,027 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

No . it's not for assembly .

在原帖中查看解决方案

0 项奖励
回复
12 回复数
3,027 次查看
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 项奖励
回复
3,027 次查看
IlConte
Contributor IV

For c language OK.

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

dc.b __DATE__
0 项奖励
回复
3,028 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

No . it's not for assembly .

0 项奖励
回复
3,027 次查看
IlConte
Contributor IV

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

Thanks

0 项奖励
回复
3,027 次查看
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 项奖励
回复
3,027 次查看
IlConte
Contributor IV

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

Thanks all

0 项奖励
回复
3,027 次查看
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 项奖励
回复
3,027 次查看
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 项奖励
回复
3,027 次查看
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 项奖励
回复
3,027 次查看
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 项奖励
回复
3,027 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome

0 项奖励
回复
3,027 次查看
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 项奖励
回复