Line | |
---|
1 | ! memset() Author: Kees J. Bot
|
---|
2 | ! 27 Jan 1994
|
---|
3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
4 |
|
---|
5 | ! void *memset(void *s, int c, size_t n)
|
---|
6 | ! Set a chunk of memory to the same byte value.
|
---|
7 | !
|
---|
8 | .sect .text
|
---|
9 | .define _memset
|
---|
10 | _memset:
|
---|
11 | push bp
|
---|
12 | mov bp, sp
|
---|
13 | push di
|
---|
14 | mov di, 4(bp) ! The string
|
---|
15 | movb al, 6(bp) ! The fill byte
|
---|
16 | mov cx, 8(bp) ! Length
|
---|
17 | cld
|
---|
18 | cmp cx, #16
|
---|
19 | jb sbyte ! Don't bother being smart with short arrays
|
---|
20 | test di, #1
|
---|
21 | jnz sbyte ! Bit 0 set, use byte store
|
---|
22 | sword: movb ah, al ! One byte to two bytes
|
---|
23 | sar cx, #1
|
---|
24 | rep stos ! Store words
|
---|
25 | adc cx, cx ! One more byte?
|
---|
26 | sbyte:
|
---|
27 | rep stosb ! Store bytes
|
---|
28 | done: mov ax, 4(bp) ! Return some value you have no need for
|
---|
29 | pop di
|
---|
30 | pop bp
|
---|
31 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.