News:

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

.for, .endfor MACROS

Started by habran, April 19, 2012, 09:53:44 PM

Previous topic - Next topic

habran

I have realized that some of people are not interested in x64
so I decided to post this here because I would like you to test it
and decide if we can use it as a standard
please give me a feedback and suggestions if any
Here are some examples:
xstrlenA PROC wpString:PTR CHAR
  .if (!wpString)
   xor eax,eax
   jmp aexit
  .endif
  .for (eax=wpString:BYTE PTR[eax]:eax++)
  .endfor
  sub eax,wpString
aexit:
  ret
xstrlenA ENDP
profor!xstrlenA:
00401194 55              push    ebp
00401195 8bec            mov     ebp,esp
00401197 837d0800        cmp     dword ptr [ebp+8],0
0040119b 7504            jne     profor!xstrlenA+0xd (004011a1)
0040119d 33c0            xor     eax,eax
0040119f eb12            jmp     profor!xstrlenA+0x1f (004011b3)
004011a1 8b4508          mov     eax,dword ptr [ebp+8]
004011a4 eb03            jmp     profor!xstrlenA+0x15 (004011a9)
004011a6 83c001          add     eax,1
004011a9 803800          cmp     byte ptr [eax],0
004011ac 7402            je      profor!xstrlenA+0x1c (004011b0)
004011ae ebf6            jmp     profor!xstrlenA+0x12 (004011a6)
004011b0 2b4508          sub     eax,dword ptr [ebp+8]
004011b3 c9              leave
004011b4 c20400          ret     4
;----------------------------------------------------------------------
xstrlenW PROC wpString:PTR wchar_t
  .if (!wpString)
   xor eax,eax
   jmp aexit
  .endif
  .for (eax=wpString:WORD PTR[eax]:eax+=2)
  .endfor
  sub eax,wpString
  sar eax,1
aexit:
  ret
xstrlenW ENDP
;----------------------------------------------------------------------

profor!xstrlenW:
004011b7 55              push    ebp
004011b8 8bec            mov     ebp,esp
004011ba 837d0800        cmp     dword ptr [ebp+8],0
004011be 7504            jne     profor!xstrlenW+0xd (004011c4)
004011c0 33c0            xor     eax,eax
004011c2 eb15            jmp     profor!xstrlenW+0x22 (004011d9)
004011c4 8b4508          mov     eax,dword ptr [ebp+8]
004011c7 eb03            jmp     profor!xstrlenW+0x15 (004011cc)
004011c9 83c002          add     eax,2
004011cc 66833800        cmp     word ptr [eax],0
004011d0 7402            je      profor!xstrlenW+0x1d (004011d4)
004011d2 ebf5            jmp     profor!xstrlenW+0x12 (004011c9)
004011d4 2b4508          sub     eax,dword ptr [ebp+8]
004011d7 d1f8            sar     eax,1
004011d9 c9              leave
004011da c20400          ret     4

and here is the source code:


_________________________
I added cool smileys to this message... if you don't see them go to: http://s.exps.me