The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: agnokapathetic on April 15, 2006, 03:06:55 AM

Title: Time
Post by: agnokapathetic on April 15, 2006, 03:06:55 AM
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
Title: Re: Time
Post by: GregL on April 15, 2006, 03:36:42 AM
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

Title: Re: Time
Post by: MichaelW on April 15, 2006, 04:23:22 AM
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