Hi there all,

Newbie ASM coder here who needs some constructive criticism! I have been working with the ListView control recently and using alot of dates and have found it alot easier to sort dates if I convert them to Julian Dates first. So I had a go at a Calender Date to Julian Date algo and would be very grateful if you all could have a look at it and tell me where it could be improved (as i'm sure it can!). Its based on the calculation found on this page

ok here goes..I've used the 3rd April 2001 as a test and this correctly comes out with the JD of 2452003 (with the caveat of subtracting a final half day)




.data
year dd 2001
month dd 4
day dd 3

.data?
lBuffer db 64 dup (?)
tempA dd ?
tempB dd ?
tempC dd ?
tempE dd ?
tempF dd ?

.code
start:

; *** if month = jan or feb add 12 to the month and sub 1 from the year
mov ebx,year
mov edi,month
cmp edi,3
jge cont
add edi,12
sub ebx,1

cont:

; ***** A=year/100
mov eax,ebx ;ebx=year
xor edx,edx
mov ecx,100
mov eax,ebx
div ecx
mov tempA,eax

; **** B=A/4
shr eax,2
mov tempB,eax

; *** C=(2-A)+B
mov eax,2
sub eax,tempA
add eax,tempB
mov tempC,eax

; **** 365.25*(year+4716)
mov eax,ebx ;ebx=year
mov ecx,365
mul ecx
mov ecx,ebx
shr ecx,2
add eax,ecx
add eax,1722519
mov tempE,eax

; **** F=30.6001*(month+1)
mov eax,edi ; edi=month
mov ecx,306001
inc eax
mul ecx
mov ecx,10000
xor edx,edx
div ecx
mov tempF,eax

; *** JD=C+day+E+F-1524.5 (here i ignore the .5)
mov eax,tempC
add eax,day
add eax,tempE
add eax,tempF
sub eax,1524

invoke dwtoa,eax,addr lBuffer
invoke MessageBox,0,addr lBuffer,0,0
invoke ExitProcess,0

end start

Posted on 2003-05-02 21:36:38 by MurkyT
Algo looks good. Here are some relating threads:

http://www.asmcommunity.net/board/index.php?topic=5111&highlight=date
http://www.asmcommunity.net/board/index.php?topic=4358&highlight=month+year

I made the mistake of not optimizing correctly before - I'll see what I can do with this one.
Posted on 2003-05-02 23:50:14 by bitRAKE
MurkyT

Sorry I can not hepl you with optimization, but I am trying to write a date dll and I am using the algorithm from this site http://www.hermetic.ch/cal_stud/jdn.htm#comp

I think it is easier to work with Julian Numbers

I can post my dll if you want to look at it but it is not very well writen
Posted on 2003-05-05 19:10:32 by Nightjada