Assembly Language for Beginners

(Jeff_L) #1

1.24. STRUCTURES


1.24.1 MSVC: SYSTEMTIME example.


Let’s take the SYSTEMTIME^158 win32 structure that describes time.


This is how it’s defined:


Listing 1.325: WinBase.h

typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;


Let’s write a C function to get the current time:


#include <windows.h>
#include <stdio.h>


void main()
{
SYSTEMTIME t;
GetSystemTime (&t);


printf ("%04d-%02d-%02d %02d:%02d:%02d\n",
t.wYear, t.wMonth, t.wDay,
t.wHour, t.wMinute, t.wSecond);

return;
};


We get (MSVC 2010):


Listing 1.326: MSVC 2010 /GS-

_t$ = -16 ; size = 16
_main PROC
push ebp
mov ebp, esp
sub esp, 16
lea eax, DWORD PTR _t$[ebp]
push eax
call DWORD PTR impGetSystemTime@4
movzx ecx, WORD PTR _t$[ebp+12] ; wSecond
push ecx
movzx edx, WORD PTR _t$[ebp+10] ; wMinute
push edx
movzx eax, WORD PTR _t$[ebp+8] ; wHour
push eax
movzx ecx, WORD PTR _t$[ebp+6] ; wDay
push ecx
movzx edx, WORD PTR _t$[ebp+2] ; wMonth
push edx
movzx eax, WORD PTR _t$[ebp] ; wYear
push eax
push OFFSET $SG78811 ; '%04d-%02d-%02d %02d:%02d:%02d', 0aH, 00H
call _printf
add esp, 28
xor eax, eax
mov esp, ebp
pop ebp
ret 0
_main ENDP


(^158) MSDN: SYSTEMTIME structure

Free download pdf