|
|
1.1 root 1: .intelorder
2: //////////
3: / libc/string/i386/memset.s
4: / i386 C string library.
5: / ANSI 4.11.6.1.
6: //////////
7:
8: //////////
9: / void *
10: / memset(void *String, int Char, size_t Count)
11: /
12: / Set Count bytes of String to Char.
13: / Uses repeated dword copy for efficiency.
14: //////////
15:
16: String .equ 12
17: Char .equ String+4
18: Count .equ Char+4
19:
20: .text
21: .globl memset
22:
23: memset:
24: push %edi
25: push %es / save es
26: push %ds / copy ds to es
27: pop %es
28:
29: movl %edi, String(%esp) / String address to EDI
30:
31: movzxb %eax, Char(%esp) / Char to EAX
32: movl %ecx, $0x01010101 / Char:Char:Char:Char in EAX
33: mull %eax, %ecx / Char:Char:Char:Char in EAX
34:
35: movl %ecx, Count(%esp) / Count to ECX
36: movl %edx, %ecx / Save Count in EDX
37: shrl %ecx, $2 / Count/4
38:
39: cld
40: rep
41: stosl / Copy Count/4 Char dwords to String
42: jnc ?byte / CF contains Count bit 1 from shrl above
43: stosw / Copy a word
44:
45: ?byte:
46: shrl %edx, $1
47: jnc ?done
48: stosb / Copy Char to String
49:
50: ?done:
51: movl %eax, String(%esp) / Return the destination in EAX
52:
53: pop %es / restore es
54: pop %edi
55: ret
56:
57: / end of libc/string/i386/memset.s
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.