I want to create a file in x86 assembler, with a filename from a system time.
I know that in order to get time I have to use function 2 from interrupt 1Ah – it returns the time in registers. The problem I have is with creating a file with contents of this registers.
Function 3ch from interrupt 21h uses filename, that is stored in DX register, but the filename has to be in ASCII.
How can I convert the data to ASCII? Or is there some other way?
Thanks.
I want to create a file in x86 assembler, with a filename from a
Share
If you read the real time clock time with int 1Ah fn 2, you will get the time in 55 millisecond intervals since midnight, and you are going to have to do all the necessary computations by yourself in order to compute hours, minutes and seconds out of it. It is not rocket science, but why not avoid it if you can?
Luckily, you can use int 21h, fn 2C “DOS Get Time” which returns the hour in CH, the minutes in CL, the seconds in DH, and even (a miserable approximation of) hundredths of a second in DL. (Okay, ignore DL.) So then, all you have to do is convert these numbers to a string, in order to build your filename.
Now, it is not correct to say that the filename is stored in the DX register; the filename is going to have to be stored in a buffer, and the DX register will need to point to that buffer upon entry to int 21h fn 3Ch.
Converting a number to ASCII is tricky business, but luckily it has been answered before on SO: Problem converting integer to ASCII code in x86 assembly