News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

\masm32\DateTime\DayOfWeek.ASM

Started by herge, November 17, 2009, 12:44:29 PM

Previous topic - Next topic

herge

 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

// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

GregL

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.


herge

// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

GregL

#3
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.




Larry Hammick

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
;...