69,371
社区成员
发帖
与我相关
我的任务
分享
#define ARRAYSIZE 2048
void main()
{
char arrayA[ARRAYSIZE] = {0};
char arrayB[ARRAYSIZE];
memset(array, 0, ARRAYSIZE);
}
4 : char a[16]={0};
mov BYTE PTR _a$[ebp], 0
xor eax, eax
mov DWORD PTR _a$[ebp+1], eax
mov DWORD PTR _a$[ebp+5], eax
mov DWORD PTR _a$[ebp+9], eax
mov WORD PTR _a$[ebp+13], ax
mov BYTE PTR _a$[ebp+15], al
; 5 :
; 6 : char b[16];
; 7 : memset(b,0,sizeof(b));
push 16 ; 00000010H
push 0
lea ecx, DWORD PTR _b$[ebp]
push ecx
call _memset
add esp, 12 ; 0000000cH
; 8 :
; 9 : char c[16]={};
xor edx, edx
mov DWORD PTR _c$[ebp], edx
mov DWORD PTR _c$[ebp+4], edx
mov DWORD PTR _c$[ebp+8], edx
mov DWORD PTR _c$[ebp+12], edx
; 4 : char a[100]={0};
mov BYTE PTR _a$[ebp], 0
push 99 ; 00000063H
push 0
lea eax, DWORD PTR _a$[ebp+1]
push eax
call _memset
add esp, 12 ; 0000000cH
; 5 :
; 6 : char b[100];
; 7 : memset(b,0,sizeof(b));
push 100 ; 00000064H
push 0
lea ecx, DWORD PTR _b$[ebp]
push ecx
call _memset
add esp, 12 ; 0000000cH
; 8 :
; 9 : char c[100]={};
push 100 ; 00000064H
push 0
lea edx, DWORD PTR _c$[ebp]
push edx
call _memset
add esp, 12 ; 0000000cH
; 4 : char a[100]={0};
mov BYTE PTR _a$[ebp], 0
push 99 ; 00000063H
push 0
lea eax, DWORD PTR _a$[ebp+1]
push eax
call _memset
add esp, 12 ; 0000000cH
; 5 :
; 6 : char b[100];
; 7 : memset(b,0,sizeof(b));
push 100 ; 00000064H
push 0
lea ecx, DWORD PTR _b$[ebp]
push ecx
call _memset
add esp, 12 ; 0000000cH
; 8 :
; 9 : char c[100]={};
push 100 ; 00000064H
push 0
lea edx, DWORD PTR _c$[ebp]
push edx
call _memset
add esp, 12 ; 0000000cH
#include <string.h>
#include <memcopy.h>
#undef memset
void *
memset (dstpp, c, len)
void *dstpp;
int c;
size_t len;
{
long int dstp = (long int) dstpp;
if (len >= 8)
{
size_t xlen;
op_t cccc;
cccc = (unsigned char) c;
cccc |= cccc << 8;
cccc |= cccc << 16;
if (OPSIZ > 4)
/* Do the shift in two steps to avoid warning if long has 32 bits. */
cccc |= (cccc << 16) << 16;
/* There are at least some bytes to set.
No need to test for LEN == 0 in this alignment loop. */
while (dstp % OPSIZ != 0) // 使dstp对齐为OPSIZ的整数倍。
{
((byte *) dstp)[0] = c;
dstp += 1;
len -= 1;
}
/* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */
xlen = len / (OPSIZ * 8); //一次写8个op_t,如果op_t是4,一次写32字节,
while (xlen > 0) //如果op_t是8,一次写64字节
{
((op_t *) dstp)[0] = cccc;
((op_t *) dstp)[1] = cccc;
((op_t *) dstp)[2] = cccc;
((op_t *) dstp)[3] = cccc;
((op_t *) dstp)[4] = cccc;
((op_t *) dstp)[5] = cccc;
((op_t *) dstp)[6] = cccc;
((op_t *) dstp)[7] = cccc;
dstp += 8 * OPSIZ;
xlen -= 1;
}
len %= OPSIZ * 8;
/* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */
xlen = len / OPSIZ; //可能还有剩下的几个op_t没有初始化的,肯定小于8个
while (xlen > 0)
{
((op_t *) dstp)[0] = cccc;
dstp += OPSIZ;
xlen -= 1;
}
len %= OPSIZ;
}
/* Write the last few bytes. */
while (len > 0)//可能还有几个字节没有初始化
{
((byte *) dstp)[0] = c;
dstp += 1;
len -= 1;
}
return dstpp;
}
char *
simple_memset (char *s, int c, size_t n)
{
char *r = s, *end = s + n;
while (r < end)
*r++ = c;
return s;
}