Consists of simple functions and simple sorts written in embedded assembly in C++.
Uses MSVC inline assembly (__asm, Intel x86).
Tested in Windows / Visual Studio 2017
Add both pairs to your project:
assembly_inline_functions.h+assembly_inline_functions.cppassembly_sort_functions.h+assembly_sort_functions.cpp
| Function | Returns | Instruction(s) |
|---|---|---|
Add(a, b) |
int |
add |
Sub(a, b) |
int |
sub |
Mul(a, b) |
__int64 |
mul (EDX:EAX) |
Div(a, b) |
int |
div (64-bit a → EDX:EAX, divide by b) |
Equal, Greater, GreaterEqual, Lower, LowerEqual |
bool |
cmp + branch |
Not, And, Or, Xor |
bool |
not / and / or / xor on AL |
Index(arr, i) |
int |
[ebx + eax*4] |
LLShift, RLShift(a, count) |
int |
shl, shr |
LCShift, RCShift(a, count) |
int |
rol, ror |
Shift count is __int8 (loaded into CL).
In-place ascending sort. n = number of int elements.
| Function | Algorithm |
|---|---|
AssemblerBubbleSort(adress, n) |
bubble |
AssemblerSelectionSort(adress, n) |
selection |
Example:
int arr[] = { 5, 2, 8, 1 };
AssemblerBubbleSort(arr, 4); // arr is modifiedThe pointer parameter is spelled adress in the headers — keep it when calling.