Please crit, if you see pitfalls with what I'm doing. I played around a little with different sources can came up with this 'old school' algo.

Attempting to emulate memset() from the C runtime...

here is MSDN ref:
void *memset(
void *dest,
int c,
size_t count
);

return value is destination.. what the heck does that mean?

here is my C++/asm stuff:

extern "C" int __cdecl MemSet(void *, int, int);

MemSet(src2,'*',5); <===== seems to work ok

MemSet proc public uses edi Dst:PTR BYTE,cha:DWORD,LN:DWORD

; ---------------------------------------------------------
; Set string Dst 'LN', from beginning, to specified char in dest
; ~~ ~~~~~~ ~~~~
; USAGE:
; invoke StrLen,ADDR Dst, DWORD cha, DWORD LN
;
; NOTE: Source buffer should be null-terminated(0)
; ---------------------------------------------------------

mov edi,
xor ecx,ecx
xor eax,eax
mov eax, cha

@loop:
mov , al
inc ecx
cmp ecx,LN
jne @loop

ret

MemSet endp
Posted on 2003-04-12 02:22:17 by drarem
rep stosb could be better. :)

BTW, unless you are trying to test yourself, search the forum about memset(). It has been discussed many times.
Posted on 2003-04-12 02:26:37 by Starless
Posted on 2003-04-12 02:50:32 by roticv
thanks, easy enough for me to understand. I also see it's a big foodchain, I usually blast people (in a polite way) on the C forums for what I just asked lol.

cld ; get the edi incrementing
mov edi, ; get the string
mov ecx,LN ; get the length
mov eax, cha ; copy cha to the eax reg
rep stosb ; store al into edi,

ret

I'll try STOSD later on, when I can visualize the AND masking the last byte/storing the last byte if it's not an even dword.
Posted on 2003-04-12 02:57:10 by drarem