Added Code

This commit is contained in:
William Welna
2012-11-10 11:09:14 -05:00
commit 2b1aa6a8ed
4 changed files with 467 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
+163
View File
@@ -0,0 +1,163 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store
+243
View File
@@ -0,0 +1,243 @@
; Simple String Functions in Assembly
;
; Copyright (C) 2012, William H. Welna All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; ; Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; ; Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY William H. Welna ''AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL William H. Welna BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
section .txt
; global declarations
global myxor
global myxorr
global myinv
global mycpy
global myset
global myzero
global mycmp
global mylen
global mycat
global find
myinv: ; void __cdecl myinv(void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov esi, [ebp+8] ; buff
mov edi, esi; ; dest is src
mov ecx, [ebp+12] ; len
mov ah, 0xFF ; invert
.loop:
lodsb
xor al, ah
stosb
loop .loop
pop esi
pop edi
mov esp, ebp
pop ebp
ret
myxor: ; void __cdecl myxor(void *, unsigned int, char);
push ebp
mov ebp, esp
push edi
push esi
mov esi, [ebp+8] ; buff
mov edi, esi; ; dest is src
mov ecx, [ebp+12] ; len
mov ah, [ebp+16] ; char to xor
.loop:
lodsb
xor al, ah
stosb
loop .loop
pop esi
pop edi
mov esp, ebp
pop ebp
ret
myxorr: ; void __cdecl myxorr(char, void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov ah, [ebp+8] ; char to xor
mov esi, [ebp+12] ; buff
mov edi, esi; ; dest is src
mov ecx, [ebp+16] ; len
.loop:
lodsb
xor al, ah
stosb
loop .loop
pop esi
pop edi
mov esp, ebp
pop ebp
ret
mycpy: ; void __cdecl *mycpy(void *, void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov edi, [ebp+8] ; dest
mov esi, [ebp+12] ; src
mov ecx, [ebp+16] ; size
cld
rep movsb
mov eax, [ebp+8]
pop esi
pop edi
mov esp, ebp
pop ebp
ret
myset: ; void __cdecl *myset(void *, char, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov edi, [ebp+8] ; dest
mov al, [ebp+12] ; char
mov ecx, [ebp+16] ; size
cld
rep stosb
mov eax, [ebp+8] ; return dest
pop esi
pop edi
mov esp, ebp
pop ebp
ret
myzero: ; void __cdecl *myzero(void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov edi, [ebp+8] ; dest
mov ecx, [ebp+12] ; size
xor al, al ; zero!
cld
rep stosb
mov eax, [ebp+8] ; return dest
pop esi
pop edi
mov esp, ebp
pop ebp
ret
mycmp: ; int __cdecl mycmp(void *, void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
xor eax, eax
mov esi, [ebp+8] ; string 1
mov edi, [ebp+12] ; string 2
mov ecx, [ebp+16] ; size
cld
repe cmpsb
jne .ne
inc eax
.ne:
pop esi
pop edi
mov esp, ebp
pop ebp
ret
mylen: ; int __cdecl mylen(void *);
push ebp
mov ebp, esp
push edi
push esi
xor eax, eax ; \0 byte
mov edi, [ebp+8] ; string
mov ecx, 0xFFFFFFFF
cld
repne scasb
mov eax, [ebp+8]
xchg eax, edi
sub eax, edi
dec eax ; don't count the \0 byte
pop esi
pop edi
mov esp, ebp
pop ebp
ret
mycat: ; void __cdecl mycat(void *, void *, unsigned int)
push ebp
mov ebp, esp
push edi
push esi
mov eax, [ebp+8]
push eax
call mylen
add esp, 4
add eax, [ebp+8] ; string 1 + mylen(string 1)
mov ecx, [ebp+12] ; string 2
mov edx, [ebp+16] ; len
push edx
push ecx
push eax
call mycpy
add esp, 12
pop esi
pop edi
mov esp, ebp
pop ebp
ret
find: ; void __cdecl myfind(void *, unsigned int, void *, unsigned int);
push ebp
mov ebp, esp
push edi
push esi
mov ecx, [ebp+12] ; size of haystack
mov eax, [ebp+20] ; size of needle
cmp eax, ecx
jg .donejg ; if needle is larger than heystack return
sub ecx, eax ; subtract haystack size from needle
xor eax, eax
.for:
push eax
push ecx
mov eax, [ebp+20] ; needle size
mov ecx, [ebp+16] ; needle
mov edx, [ebp+8] ; haystack
push eax
push ecx
push edx
call mycmp
add esp, 12
cmp eax, 1
jne .nada
mov eax, [ebp+8] ; haystack
;add eax, [ebp+20] ; haystack + needle size
jmp .done
.nada:
inc dword [ebp+8] ; inc haystack pointer
pop ecx
pop eax
inc eax
cmp eax, ecx
jne .for
.donejg: ; special jump to make sure eax returns null
xor eax, eax ; return null
.done:
pop esi
pop edi
mov esp, ebp
pop ebp
ret
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2012, William H. Welna All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY William H. Welna ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL William H. Welna BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ASM__STUFF__
#define __ASM__STUFF__
void __cdecl *mycpy(void *, void *, unsigned int);
void __cdecl *myset(void *, char, unsigned int);
void __cdecl *myzero(void *, unsigned int);
int __cdecl mycmp(void *, void *, unsigned int);
int __cdecl mylen(void *);
void __cdecl mycat(void *, void *, unsigned int);
void __cdecl *find(void *, unsigned int, void *, unsigned int);
void __cdecl myxor(void *, unsigned int, char);
void __cdecl myxorr(char, void *, unsigned int);
void __cdecl myinv(void *, unsigned int);
#define myfind(a, b, c, d) find(a, b, c, d)
#endif