News:

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

Is This a Good Idea ?

Started by baltoro, April 25, 2011, 10:46:19 PM

Previous topic - Next topic

jj2007

One of my many mistakes is that I mess up with ret and retn:

MyTest proc arg1:DWORD, arg2:DWORD
LOCAL lv1:DWORD, lv2, lv3
  mov lv1, ecx
  mov lv2, eax
  mov lv3, edx
  MsgBox 0, arg1, arg2, MB_OK
  int 3
  retn 4
  ret 4
  ret
MyTest endp


0040101E  |$  55            push ebp                                 ; SkelBoxProc.0040101E(guessed Arg1)
0040101F  |.  8BEC          mov ebp, esp
00401021  |.  83EC 0C       sub esp, 0C
00401024  |.  894D FC       mov [ebp-4], ecx
00401027  |.  8945 F8       mov [ebp-8], eax
0040102A  |.  8955 F4       mov [ebp-0C], edx
0040102D  |.  6A 00         push 0                                   ; /Type = MB_OK|MB_DEFBUTTON1|MB_APPLMODAL
0040102F  |.  FF75 0C       push dword ptr [ebp+0C]                  ; |Caption
00401032  |.  FF75 08       push dword ptr [ebp+8]                   ; |Text
00401035  |.  6A 00         push 0                                   ; |hOwner = NULL
00401037  |.  E8 10000000   call <jmp.&user32.MessageBoxA>           ; \USER32.MessageBoxA
0040103C  |.  CC            int3
0040103D  \.  C2 0400       retn 4                                   ; ntdll.KiFastSystemCallRet
00401040  /.  8BE5          mov esp, ebp
00401042  |.  5D            pop ebp
00401043  \.  C2 0400       retn 4
00401046  /.  8BE5          mov esp, ebp
00401048  |.  5D            pop ebp
00401049  \.  C2 0800       retn 8

baltoro

One error I've NEVER made (mainly because I'm too much of an idiot), is to specify the incorrect alignment (or a default) for a data structure. But, this is an insidious error. So, I've included here some relavant information.   
Windows Data Alignment on IPF, x86, and x64, MSDN
What Structure Packing Do the Windows SDK Header Files Expect? Raymond Chen

And, here are some MASM threads that describe aspects of the problem:   
Unevenly Aligned Stack
/ALIGN:8 Does Not Work on x64 Windows 7
Memory Alignment
LocalAlloc Memory Begin (excellent code examples)
Baltoro

jj2007

See here for MichaelW's example (DialogBoxIndirectParam) how too much alignment can cause problems.

baltoro

#18
Dang,...good point JJ (it's Jochen, isn't it ?),...
Just goes to show you how little I know about MASM syntax and structure,...
...And, I was going to add an entry on race conditions and deadlocks,... :bg
Maybe, I'll have to do some more research first,...seeing as how I've actually written very few multi-threaded applications,... :eek

I should do an entry on which register values get altered by invoked Windows APIs, since, EVERYBODY makes that error at some point. Click on JJ's Website (Masm32 Tips, Tricks, and Traps, at the bottom of his last thread entry) for a description of that one.
Baltoro