-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Seb
committed
Apr 9, 2018
1 parent
efbef1d
commit cdc86c1
Showing
18 changed files
with
523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
NAME = libasm.so | ||
|
||
SRC_DIR = ./src | ||
|
||
SRC_EXT = S | ||
|
||
SRCS = src/memmove.S \ | ||
src/strstr.S \ | ||
src/strncmp.S \ | ||
src/strlen.S \ | ||
src/strcspn.S \ | ||
src/strcmp.S \ | ||
src/memset.S \ | ||
src/strcasecmp.S \ | ||
src/memcpy.S \ | ||
src/strchr.S \ | ||
src/strpbrk.S \ | ||
src/rindex.S \ | ||
src/strcpy.S \ | ||
src/strnlen.S \ | ||
src/strrchr.S \ | ||
src/bzero.S | ||
|
||
|
||
OBJS = $(SRCS:.$(SRC_EXT)=.o) | ||
|
||
RM = -rm -rf | ||
|
||
CC = gcc | ||
|
||
CFLAGS = -f macho64 | ||
|
||
all : $(NAME) | ||
|
||
$(NAME) : $(OBJS) | ||
$(CC) -o $(NAME) -shared $(OBJS) | ||
|
||
%.o : %.S | ||
nasm $(CFLAGS) -o $@ $< | ||
|
||
clean : | ||
$(RM) $(OBJS) | ||
|
||
fclean : clean | ||
$(RM) $(NAME) | ||
|
||
re : fclean all | ||
|
||
.PHONY : fclean clean all re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[BITS 64] | ||
global bzero | ||
|
||
section .text | ||
|
||
bzero: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
dec rsi | ||
loop: cmp rsi, -1 | ||
je end | ||
mov byte[rdi + rsi], 0 | ||
dec rsi | ||
jmp loop | ||
|
||
end: mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[BITS 64] | ||
global memcpy | ||
|
||
section .text | ||
|
||
memcpy: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx, rcx | ||
loop: cmp rdx, 0 | ||
jz end | ||
mov al, [rsi + rcx] | ||
mov [rdi + rcx], al | ||
inc rcx | ||
dec rdx | ||
jmp loop | ||
|
||
end: mov rax,rdi | ||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[BITS 64] | ||
global memmove | ||
|
||
section .text | ||
|
||
memmove: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
init: xor rcx, rcx ;; init counter | ||
;; mov rax, rdi | ||
;; sub rax, rsi ;; get distance | ||
;; cmp rax, rdx ;; compare to length | ||
cmp rdi, rsi | ||
jbe copy_left | ||
|
||
dec rdx | ||
copy_right: cmp rdx, -1 | ||
je end | ||
mov al, byte[rsi + rdx] | ||
mov byte[rdi + rdx], al | ||
dec rdx | ||
jmp copy_right | ||
|
||
copy_left: cmp rdx, rcx | ||
je end | ||
mov al, [rsi + rcx] | ||
mov [rdi + rcx], al | ||
inc rcx | ||
jmp copy_left | ||
|
||
|
||
end: mov rax,rdi | ||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[BITS 64] | ||
global memset | ||
|
||
section .text | ||
|
||
memset: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
mov rax,rdi | ||
loop: cmp rdx, 0 | ||
jz end | ||
mov byte[rdi], sil | ||
inc rdi | ||
dec rdx | ||
jmp loop | ||
|
||
end: mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[BITS 64] | ||
global rindex | ||
|
||
section .text | ||
|
||
rindex: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
|
||
check: cmp byte[rdi+rcx], 0 | ||
jz find | ||
inc rcx | ||
jmp check | ||
|
||
find: cmp rcx, -1 | ||
je null | ||
cmp byte[rdi+rcx], sil | ||
je end | ||
dec rcx | ||
jmp find | ||
|
||
null: mov rax, 0 | ||
mov rsp, rbp | ||
pop rbp | ||
ret | ||
|
||
end: add rcx, rdi | ||
mov rax, rcx | ||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[BITS 64] | ||
global strcasecmp | ||
|
||
section .text | ||
|
||
strcasecmp: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
|
||
loop: mov al, [rdi + rcx] | ||
mov ah, [rsi + rcx] | ||
jmp check | ||
endc: jmp check2 | ||
endc2: cmp al, 0 | ||
je end | ||
cmp ah, 0 | ||
je end | ||
cmp al, ah | ||
jne end | ||
inc rcx | ||
jmp loop | ||
|
||
check: cmp al, 65 | ||
jb endc | ||
cmp al, 90 | ||
ja endc | ||
add al, 32 | ||
jmp endc | ||
|
||
check2: cmp ah, 65 | ||
jb endc2 | ||
cmp ah, 90 | ||
ja endc2 | ||
add ah, 32 | ||
jmp endc2 | ||
|
||
end: sub al, ah | ||
movsx rax, al | ||
|
||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[BITS 64] | ||
global strchr | ||
|
||
section .text | ||
|
||
strchr: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
loop: cmp byte[rdi], sil | ||
jz found | ||
cmp byte[rdi], 0 | ||
jz nfound | ||
inc rdi | ||
jmp loop | ||
|
||
found: mov rax, rdi | ||
jmp end | ||
nfound: mov rax, 0 | ||
|
||
end: mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[BITS 64] | ||
global strcmp | ||
|
||
section .text | ||
|
||
strcmp: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
loop: | ||
mov al, [rdi + rcx] | ||
mov ah, [rsi + rcx] | ||
cmp al, 0 | ||
je end | ||
cmp ah, 0 | ||
je end | ||
cmp al, ah | ||
jne end | ||
inc rcx | ||
jmp loop | ||
|
||
end: sub al, ah | ||
movsx rax, al | ||
|
||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[BITS 64] | ||
global strcpy | ||
|
||
section .text | ||
|
||
strcpy: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor r10, r10 | ||
xor r11b, r11b | ||
|
||
loop: cmp byte[rsi + r10], 0 | ||
je end | ||
mov r11b, byte[rsi + r10] | ||
mov byte[rdi + r10], r11b | ||
inc r10 | ||
jmp loop | ||
|
||
end: mov byte[rdi + r10], 0 | ||
mov rax, rdi | ||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[BITS 64] | ||
global strcspn | ||
|
||
section .text | ||
|
||
strcspn: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
|
||
loop: cmp byte[rdi+rcx], 0 | ||
je end | ||
jmp find | ||
endf: inc rcx | ||
jmp loop | ||
|
||
find: xor r10, r10 | ||
xor r11, r11 | ||
|
||
loopf: cmp byte[rsi + r10], 0 | ||
je endf | ||
cmp byte[rdi + rcx], 0 | ||
je endf | ||
mov r11b, byte[rdi + rcx] | ||
cmp byte[rsi + r10], r11b | ||
je end | ||
inc r10 | ||
jmp loopf | ||
|
||
end: mov rax, rcx | ||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[BITS 64] | ||
global strlen | ||
|
||
section .text | ||
|
||
strlen: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
check: cmp byte[rdi+rcx], 0 | ||
jz end | ||
inc rcx | ||
jmp check | ||
|
||
end: mov rax,rcx | ||
|
||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[BITS 64] | ||
global strncmp | ||
|
||
section .text | ||
|
||
strncmp: push rbp ;; prologue | ||
mov rbp, rsp | ||
|
||
xor rcx,rcx | ||
xor rax, rax | ||
loop: | ||
cmp rcx, rdx | ||
je end | ||
mov al, [rdi + rcx] | ||
mov ah, [rsi + rcx] | ||
cmp al, 0 | ||
je end | ||
cmp ah, 0 | ||
je end | ||
cmp al, ah | ||
jne end | ||
inc rcx | ||
jmp loop | ||
|
||
end: sub al, ah | ||
movsx rax, al | ||
|
||
mov rsp, rbp ;; epilogue | ||
pop rbp | ||
ret |
Oops, something went wrong.