News:

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

Time

Started by agnokapathetic, April 15, 2006, 03:06:55 AM

Previous topic - Next topic

agnokapathetic

Hey all,
I'm having a bit of trouble getting this to work correctly. What I'de like it to do is get the minute set it into the memory and compare it with the previous minute recorded. Initializing timeBuffer at 0.


checkTime PROC
LOCAL lpLocalTime :SYSTEMTIME
invoke GetLocalTime, ADDR lpLocalTime
push lpLocalTime.wMinute
pop eax
cmp eax, timeBuffer
jne different
fn MessageBox,0,"The Same",0,0
different:
push lpLocalTime.wMinute
pop timeBuffer
Ret
checkTime EndP



Am I using the correct instructions for copying memory (i.e. Push and Pop)? and branching instructions?

Thanks in advance,
--Joel

GregL

wMinute is a WORD, so you will have trouble pushing it.  Use movzx like this


checkTime PROC
    LOCAL lpLocalTime :SYSTEMTIME
    invoke GetLocalTime, ADDR lpLocalTime
    movzx eax, lpLocalTime.wMinute
    cmp eax, timeBuffer
    jne different
    fn MessageBox,0,"The Same",0,0
  different:
    movzx eax, lpLocalTime.wMinute
    push eax
    pop timeBuffer
    ret
checkTime EndP


MichaelW

Joel,

To add to Greg's reply, because lpLocalTime.wMinute is defined as a word pushing it is messing up the stack alignment, changing ESP by 2 instead of 4. For example:

mov   ebx, esp
print uhex$(ebx),13,10
push  lpLocalTime.wMinute
mov   ebx, esp
push  word ptr 0             ; fix alignment so print will work
print uhex$(ebx),13,10

Will display:

0012FFAC
0012FFAA

eschew obfuscation