NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: dbfn on February 02, 2010, 11:15:33 PM
-
So,is it possible to get a month using the Unix Time?
If it's not or there's a better way,could you teach me?
-
Are you looking to do this by manual calculations, or do you intend on using something like strftime() (http://www.cplusplus.com/reference/clibrary/ctime/strftime/)?
-
Well... not directly (that I know of). Unix tends to tell you the time in seconds since the "dawn of time" - 1/1/70. To extract a month from that, you'll need to divide by 60 a couple of times, then by 24, then by 365. Figure out how many leapyears in that, and whether "this" is a leapyear. You'll need a table of days in the months, in which February is adjusted to 29 if it's a leapyear. If you want a name, not just a number, you'll need a table of month names, too.
Here (if I can figure out how to attach a file) is an example that spits out a string similar to C. (a "challenge" suggested by Ed Beroset, IIRC). I used three-letter names for the months (and day-of-week). This requires multiplying the index by three... and adding a space after. It would have been smarter to put the spaces in the table, multiply the index by four, and have the space, too (I think).
(I don't think this is a "homework question". If it is, and you turn this in as your own work, you will almost surely get busted. Plus, you won't learn anything!)
Questions and/or critiques welcome.
Best,
Frank
-
strftime()? strftime()??? Oh yeah, dbfn is the "mixed C and asm" guy. Yeah, we could do it that way, too. Shouldn't be hard... although it does involve structures. :)
Of course, if we want to do it in a way in which somebody else has already written all the code, we could just type "date" and it'll tell us what month it is. :)
Best,
Frank
-
Hum...I'd like to do it directly.
But anyway,Frank I got a light when you said about the leapyears and the "array".It's not difficult.I'm very dumb sometimes...: |
And...by the way...I'm 15.It's no homework.I do it as a hobby.
-
I do it as a hobby, too... and I'm 65.
Somewhat less "directly", here's a version that does the easy parts "directly" in asm (int 80h), and calls C for the hard parts. Spits out the month, as requested. "Mixed C and asm", for no good reason than to see if I can. This is not the usually recommended method to write programs for Linux!
Best,
Frank