flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > new %t to string macro

Thread Post new topic Reply to topic

Joined: 05 Nov 2005
Posts: 86

Here are some macros that convert the timestamp to year/month/day:



but I have found that these macros fail in the date 31-december-2000 that they
report as 01-january-2001, so I made my own:


macro num_to_db num, digits {  ;from decard
   local ..lbl, ..ptr, ..dig, ..num 

   rb digits 

   ..ptr = ..lbl + digits - 1 
   ..num = num 
   repeat digits 
     ..dig = (..num mod 10) + $30 
     ..num = ..num / 10 
     store byte ..dig at ..ptr 
     ..ptr = ..ptr - 1 
   end repeat 
macro DayByName day
        if day=0
        db 'Sunday'
        else if day=1
        db 'Monday'
        else if day=2
        db 'Tuesday'
        else if day =3
        db 'Wednesday'
        else if day=4
        db  'Thursday'
        else if day=5
        db 'Friday'
        db 'Saturday'
        end if
macro MonthByName month
        if month = 1
           db 'January'
        else if month = 2
           db 'February'
        else if month = 3
           db 'March'
        else if month = 4
           db 'April'
        else if month = 5
           db 'May'
        else if month = 6
           db 'June'
        else if month = 7
           db 'July'
        else if month = 8
           db 'August'
        else if month = 9
           db 'September'
        else if month = 10
           db 'October'
        else if month = 11
           db 'November'
           db 'December'
        end if
macro get_time

time = %t   ;add or sub your timezone here

        SECONDS = time mod 60
           min = time/60
        MINUTES  = min mod 60
           hora = min/60
        HOURS = hora mod 24
           dias = hora/24
        DAYWEEK=(dias mod 7)+4
        if DAYWEEK >6
          DAYWEEK =DAYWEEK-7
        end if

YEAR = 1970
while 1
        if (YEAR mod 4 = 0) & (YEAR <>2100)
                if dias>=366
                        dias = dias-366
                        YEAR = YEAR +1
                end if
                if dias>=365
                end if
        end if

end while

if (YEAR mod 4 = 0) & (YEAR <> 2100)
end if
dias = dias +1

virtual at 1
db 31,feb,31,30,31,30,31,31,30,31,30,31
DAY = dias
repeat 12
load MONTH byte from %
        if DAY>MONTH
           MONTH = %
        end if
end repeat
end virtual


if the code above is saved to a file 'time.inc' and included in a project, calling
the 'get_time' macro will load the variables with the corresponding values from %t:

YEAR the year form 1970 to 2106
MONTH form 1 to 12
DAY from 1 to 31
HOURS from 0 to 23
MINUTES from 0 to 59
SECONDS from 0 to 59
DAYWEEK from 0 to 6 as 0 = sunday,1 = monday ...

the macro works ok for timestamp 0 =
Thursday 01/january/1970 00:00:00
to timestamp FFFFFFFFh =
sunday 7/february/2106 06:28:15

you can use these variables to define the values as binary data or ascii.
here is an example of using the macro to define them as string.

the time.inc contains 2 simple macros to define the names of the months
and days of the week based on their numbers,i also include a num_to_db macro
from decard to define the strings of the other values:


format pe gui
include 'win32ax.inc'
include 'time.inc'
get_time   ;load values

     invoke MessageBoxA,0,date,title,MB_OK
     invoke ExitProcess, 0

title db 'TimeStamp test',0

db ' '
num_to_db DAY,2
db '/'
num_to_db MONTH,2
db '/'
num_to_db YEAR,4
db ' '
num_to_db HOURS,2
db ':'
num_to_db MINUTES,2
db ':'
num_to_db SECONDS,2
db 13,10,'('
MonthByName MONTH
db ')',0

.end start


obviously the format can be customized at will, but don't forget to put the final 0
and add or substract the correct number of secons to the %t acording to your timezone.
Post 12 Aug 2007, 22:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.