The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: herge on November 17, 2009, 12:44:29 PM

Title: \masm32\DateTime\DayOfWeek.ASM
Post by: herge on November 17, 2009, 12:44:29 PM
 Hi *.*:


DayOfWeek PROC pdt:PTR DATETIME

    ; Return in eax
    ; Sunday = 0, Monday = 1, ... Saturday = 6
   
    LOCAL _st:SYSTEMTIME
   
    INVOKE FileTimeToSystemTime, pdt, ADDR _st
    .IF eax == 0
        xor eax, eax
    .ELSE   
        movzx eax, _st.wDayOfWeek
    .ENDIF   
    ret   
DayOfWeek ENDP



I am pretty sure that
.IF eax == 0
       mov eax, -1; dec eax Will work if eax always zero

Regards: herge

Title: Re: \masm32\DateTime\DayOfWeek.ASM
Post by: GregL on November 18, 2009, 03:50:09 AM
Hi Herge,

It should return -1 and not 0 on error.  The help file says it returns -1 on error.  Thanks for noticing that.


DayOfWeek PROC pdt:PTR DATETIME

    ; Return in eax
    ; Sunday = 0, Monday = 1, ... Saturday = 6
   
    LOCAL _st:SYSTEMTIME
   
    INVOKE FileTimeToSystemTime, pdt, ADDR _st
    .IF eax == 0
        mov eax, -1
    .ELSE   
        movzx eax, _st.wDayOfWeek
    .ENDIF   
    ret   
DayOfWeek ENDP


I changed my copy of the code.  Now we just need to get the MASM32 copy of the code changed.

Title: Re: \masm32\DateTime\DayOfWeek.ASM
Post by: herge on November 18, 2009, 04:21:50 AM

Hi Greg:

Thanks!

Regards: herge



Title: Re: \masm32\DateTime\DayOfWeek.ASM
Post by: GregL on November 18, 2009, 04:33:21 AM
Herge,

For now you can just make the correction in the DayOfWeek.asm file and then run \masm32\DateTime\make.bat to rebuild the DateTime.lib file and copy it to the masm32\lib directory.



Title: Re: \masm32\DateTime\DayOfWeek.ASM
Post by: Larry Hammick on December 10, 2009, 08:10:43 AM
In the same vein, a routine might want to return 0 if one of its subroutines returns -1. E.g.
; C source:
; ...
; hFile = CreateFile(fname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
; if (hFile == NULL || hFile == (HANDLE)-1) {
; return 0;
; ...

invoke CreateFileA,address fname, GENERIC_WRITE,0,0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
inc eax
jz abort_with_eax
dec eax
jz abort_with_eax
mov hFile,eax
;...