MemUtils
In memutils.zir i found memfill routine which use only "rep stosb". It no so fast. And i try write myself memfill.
I do the same way as in strutils.zir:
function strFill(char* buf; dword dwlen; char _ch)
/*
/ Fill block of memory with specified value
/ $buf -- Pointer to block of memory to fill
/ $len -- Value to be set
/ $ch_ -- Number of bytes to set to value
/ Copyright (c) 0CodErr, KolibriOS team
*/
procedure memFill(char* buf; dword len; char _ch) {
uses edi;
eax = 0;
al = _ch;
edx = len;
edi = buf;
ecx = eax;
ah = al;
ch = cl;
ecx << 16;
or eax, ecx;
ecx = edx;
ecx >> 2;
and edx, 3;
rep stosd;
ecx = edx;
rep stosb;
return buf;
}
But when i get result executable in it was:
memFill:
0x55 push ebp
0x8bec mov ebp, esp
0x57 push edi
0x33c0 xor eax, eax
0x8a450d mov al, [ebp + 0dh]
0x8b550c mov edx, [ebp + 0ch]
0x8b7d08 mov edi, [ebp + 08h]
0x8bc8 mov ecx, eax
0x8ae0 mov ah, al
0x8ae9 mov ch, cl
0xc1e110 shl ecx, 10h
0x0bc1 or eax, ecx
0x8bca mov ecx, edx
0xc1e902 shr ecx, 02h
0x83e203 and edx, 03h
0xf3ab rep stosd
0x8bca mov ecx, edx
0xf3aa rep stosb
0x8b4508 mov eax, [ebp + 08h]
0x5f pop edi
0xc9 leave
0xc20900 ret 09h
As far as i understand
[ebp + 08h] -- buf
[ebp + 0ch] -- len
but len should be dword then 0ch + 04h = 10h
why we get
mov al, [ebp + 0dh]
?
hmm.. and also
ret 09h
As i think before call byte converted to dword.
For example:
char mychar[2] = ['p', 0];
char char1 = 0x61;
memFill(@mychar, 1, char1);
Result:
0x33c0 xor eax, eax
0xa002204000 mov al, byte ptr [loc_00402002]
0x50 push eax
0x6a01 push 01h
0x6800204000 push 402000h
0xe80c010000 call memFill