Skip to content

Commit

Permalink
[Reduction] #221-222: memset
Browse files Browse the repository at this point in the history
Two functions, just differing in their order of parameters. It's...
convenient, I guess?
  • Loading branch information
nmlgc committed Aug 27, 2014
1 parent 444901a commit f3e9147
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 1,127 deletions.
60 changes: 60 additions & 0 deletions libs/BorlandC/memset.asm
@@ -0,0 +1,60 @@
; void __cdecl setmem(void *addr, unsigned int len, char val)
public _setmem
_setmem proc DIST
@@addr = dword ptr 6
@@len = word ptr 0Ah
@@val = byte ptr 0Ch

push bp
mov bp, sp
push si
push di
LES_ di, [bp+@@addr]
mov cx, [bp+@@len]
mov al, [bp+@@val]
mov ah, al
cld
test di, 1
jz short @@isAligned
jcxz short @@done
stosb
dec cx

@@isAligned:
shr cx, 1
rep stosw
jnb short @@noOdd
stosb

@@noOdd:
@@done:
pop di
pop si
pop bp
ret
_setmem endp

; void *__cdecl memset(void *src, int c, size_t n)
public _memset
_memset proc DIST
@@src = dword ptr 6
@@c = byte ptr 0Ah
@@n = word ptr 0Ch

push bp
mov bp, sp
push si
push di
push word ptr [bp+@@c]
push [bp+@@n]
push word ptr [bp+@@src+2]
push word ptr [bp+@@src]
call _setmem
add sp, 8
mov dx, word ptr [bp+@@src+2]
mov ax, word ptr [bp+@@src]
pop di
pop si
pop bp
ret
_memset endp
76 changes: 2 additions & 74 deletions th01_fuuin.asm
Expand Up @@ -8806,77 +8806,7 @@ _getenv endp

include libs/BorlandC/memcmp.asm
include libs/BorlandC/memcpy.asm

; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void __cdecl setmem(void *dest, unsigned int length, char value)
_setmem proc far

dest = dword ptr 6
_length = word ptr 0Ah
value = byte ptr 0Ch

push bp
mov bp, sp
push si
push di
les di, [bp+dest]
mov cx, [bp+_length]
mov al, [bp+value]
mov ah, al
cld
test di, 1
jz short loc_4947
jcxz short loc_494E
stosb
dec cx

loc_4947:
shr cx, 1
rep stosw
jnb short loc_494E
stosb

loc_494E:
pop di
pop si
pop bp
retf
_setmem endp


; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void *__cdecl memset(void *s, int c, size_t n)
_memset proc far

dest = dword ptr 6
value = byte ptr 0Ah
_length = word ptr 0Ch

push bp
mov bp, sp
push si
push di
push word ptr [bp+value] ; value
push [bp+_length] ; length
push word ptr [bp+dest+2]
push word ptr [bp+dest] ; dest
push cs
call near ptr _setmem
add sp, 8
mov dx, word ptr [bp+dest+2]
mov ax, word ptr [bp+dest]
pop di
pop si
pop bp
retf
_memset endp

include libs/BorlandC/memset.asm

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -14198,9 +14128,7 @@ loc_7674:
push ss
les bx, [bp+arg_6]
push word ptr es:[bx+36h] ; s
nop
push cs
call near ptr _memset
nopcall _memset
add sp, 8
jmp loc_77C7
; ---------------------------------------------------------------------------
Expand Down
94 changes: 7 additions & 87 deletions th01_op.asm
Expand Up @@ -8685,85 +8685,7 @@ _getenv endp

include libs/BorlandC/memcmp.asm
include libs/BorlandC/memcpy.asm

; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void __cdecl setmem(void *dest, unsigned int length, char value)
_setmem proc far

dest = dword ptr 6
_length = word ptr 0Ah
value = byte ptr 0Ch

push bp
mov bp, sp
push si
push di
les di, [bp+dest]
mov cx, [bp+_length]
mov al, [bp+value]
mov ah, al
cld
test di, 1
jz short loc_4C29
jcxz short loc_4C30
stosb
dec cx

loc_4C29:
shr cx, 1
rep stosw
jnb short loc_4C30
stosb

loc_4C30:
pop di
pop si
pop bp
retf
_setmem endp


; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void *__cdecl memset(void *s, int c, size_t n)
_memset proc near

dest = dword ptr 6
value = byte ptr 0Ah
_length = word ptr 0Ch

push bp
mov bp, sp
push si
push di
push word ptr [bp+value] ; value
push [bp+_length] ; length
push word ptr [bp+dest+2]
push word ptr [bp+dest] ; dest
push cs
call near ptr _setmem
add sp, 8
_memset endp ; sp-analysis failed


; =============== S U B R O U T I N E =======================================

; Attributes: library function

sub_4C4C proc far
mov dx, [bp+8]
mov ax, [bp+6]
pop di
pop si
pop bp
retf
sub_4C4C endp ; sp-analysis failed

include libs/BorlandC/memset.asm

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -14029,9 +13951,7 @@ loc_78EF:
push ss ; c
les bx, [bp+arg_6]
push word ptr es:[bx+36h]
nop
push cs ; s
call _memset
nopcall _memset
add sp, 8
jmp loc_7A42
; ---------------------------------------------------------------------------
Expand Down Expand Up @@ -22694,7 +22614,7 @@ _s = dword ptr -4
call near ptr sub_B976
push large 7D0000FFh ; c
push large [bp+_s] ; s
call far ptr _memset
call _memset
add sp, 0Ah
push cs
call near ptr sub_BA0A
Expand Down Expand Up @@ -22735,7 +22655,7 @@ sub_BB3C endp
call near ptr sub_B976
push large 7D0000FFh
push large dword ptr [bp-4]
call far ptr _memset
call _memset
add sp, 0Ah
push cs
call near ptr sub_BA0A
Expand Down Expand Up @@ -22891,7 +22811,7 @@ var_2 = word ptr -2
push ss
lea ax, [bp+_s]
push ax ; s
call far ptr _memset
call _memset
add sp, 8
mov [bp+var_2], 0
jmp loc_BD2E
Expand Down Expand Up @@ -23109,7 +23029,7 @@ loc_BDF4:
push ss
lea ax, [bp-32h]
push ax
call far ptr _memset
call _memset
add sp, 8
mov word ptr [bp-2], 0
jmp loc_BE9F
Expand Down Expand Up @@ -25269,7 +25189,7 @@ loc_CF49:
push ss
lea ax, [bp-34h]
push ax
call far ptr _memset
call _memset
add sp, 8
xor di, di
jmp loc_CFFD
Expand Down
80 changes: 3 additions & 77 deletions th01_reiiden.asm
Expand Up @@ -9886,9 +9886,7 @@ loc_48E8:
push [bp+_length] ; length
push word ptr [bp+dest+2]
push word ptr [bp+dest] ; dest
nop
push cs
call near ptr _setmem
nopcall _setmem
add sp, 8
mov bx, [bp+_length]
xor cx, cx
Expand Down Expand Up @@ -12392,77 +12390,7 @@ _getenv endp

include libs/BorlandC/memcmp.asm
include libs/BorlandC/memcpy.asm

; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void __cdecl setmem(void *dest, unsigned int length, char value)
_setmem proc far

dest = dword ptr 6
_length = word ptr 0Ah
value = byte ptr 0Ch

push bp
mov bp, sp
push si
push di
les di, [bp+dest]
mov cx, [bp+_length]
mov al, [bp+value]
mov ah, al
cld
test di, 1
jz short loc_5F9F
jcxz short loc_5FA6
stosb
dec cx

loc_5F9F:
shr cx, 1
rep stosw
jnb short loc_5FA6
stosb

loc_5FA6:
pop di
pop si
pop bp
retf
_setmem endp


; =============== S U B R O U T I N E =======================================

; Attributes: library function bp-based frame

; void *__cdecl memset(void *s, int c, size_t n)
_memset proc far

dest = dword ptr 6
value = byte ptr 0Ah
_length = word ptr 0Ch

push bp
mov bp, sp
push si
push di
push word ptr [bp+value] ; value
push [bp+_length] ; length
push word ptr [bp+dest+2]
push word ptr [bp+dest] ; dest
push cs
call near ptr _setmem
add sp, 8
mov dx, word ptr [bp+dest+2]
mov ax, word ptr [bp+dest]
pop di
pop si
pop bp
retf
_memset endp

include libs/BorlandC/memset.asm

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -17868,9 +17796,7 @@ loc_8D62:
push ss
les bx, [bp+arg_6]
push word ptr es:[bx+36h] ; s
nop
push cs
call near ptr _memset
nopcall _memset
add sp, 8
jmp loc_8EB5
; ---------------------------------------------------------------------------
Expand Down

0 comments on commit f3e9147

Please sign in to comment.