|
32 bit Assembly Language Extensions for Visual Prolog Please bear in mind
that this is an entirely new site,
"under construction". The important difference between this kind of "site under
construction" and most other sites
"under construction", is that this
site will consist of Source Code
which is rarely
understood by
(most) software developers, and even more
difficult to debug, if
contaminated
by typing errors, hidden bugs (=that don't manifest immediately) or
other mistakes. The contents of this site are going to grow very slowly;
even more slowly, since I also
have
a full-time job (as an A.I. researcher and software developer, in ENB Ltd).
During the last seven years (or so) I've written hundreds of 32-bit Assembly Language functions, which are candidates for inclusion in this site: Most of them will be included here in fully functional and complete source-code files. However, a small number of them will be included as DLL's or OBJ-files, for downloading, as motivation e.g. to buy the code, or to get a "better, fuller version" of it, and so on... ;). (This is particularly true for ASM implementations of certain rare novelty algorithms, such as the "Iphigenia Algorithm for bit-crunching expert system deductions", my "Tourist Sort algorithm", etc.) The important thing for us all is to share a vision, participating in an international community of programmers who still write Assembly Language code, to accomplish certain goals that (most of) today's software industry regards as far too difficult or impossible to achieve (in reasonable amounts of execution time). Well, most (non-Atlantean, Earthling-style) ;) software houses still have a long way to go, to believe that "Impossible is a myth"! (like the Adidas ad says, in Greece)! Hey, you! (sigh...) earthlings! To achieve the "impossible", you don't have to be a... Crazy Atlantean Soul, but it helps! ;-) |
|---|
| Global
Predicates: |
Source
files: |
|
| /* Fast conversions of a string into a
list-of-strings, and vice versa */ STRING conclist(SLIST,CHAR) -(i,i) language c
str2slist(STRING str,CHAR separator,STRING buffer,SLIST list) -(i,i,i,o) language c |
conclist.html (new!) str2slist.html |
|
| /*Counters and
FOR-loops in Assembler*/ nondeterm repcount(INTEGER initial_value,INTEGER out_value) -(i,o) language c nondeterm repcount(INTEGER initialVal,INTEGER finalVal,INTEGER outVal) -(i,i,o) language c |
repcount_asm.html |
|
| /*Universal, polymorphic ultra-fast conversions of
Lists to Element-arrays (and vice-versa): */ list2bin(ILIST,BINARY) -(i,i),(i,o),(o,i) language c slist2bin(SLIST,BINARY) -(i,i) language c as "_list2bin_0" slist2binx(SLIST,BINARY) -(i,o) language c as "_list2bin_1" slistx2bin(SLIST,BINARY) -(o,i) language c as "_list2bin_2" |
_list2bin.html | |
| /* Fast (deterministic) checking of
list membership (and / or list-position indexing): */ ismember(UNSIGNED,ILIST) -(i,i) language c ismember(STRING,SLIST) -(i,i) language c ismember(UNSIGNED,ILIST,UNSIGNED) -(i,i,o),(o,i,i) language c ismember(STRING,SLIST,UNSIGNED) -(i,i,o),(o,i,i) language c % Further polymorphic definitions, re-using the same code but requiring different Global Declarations: ismember(SLIST,SLL,UNSIGNED) -(o,i,i) language c as "_ismember_3" ismember(WINDOW,WINLIST,UNSIGNED) -(o,i,i) language c as "_ismember_3" ismember(PNT,PNTLIST,UNSIGNED) -(o,i,i) language c as "_ismember_3" ismember(LONG,LONGLIST) -(i,i) language c as "_ismember_0" ismember(WSFLAG,WSFLAGS) -(i,i) language c as "_ismember_0" ismember(BINARY,BLIST,UNSIGNED) -(o,i,i) language c as "_ismember_3" % (etc.) ... |
_ismember.html | |
| /*Generation of ascending number-list
sequences: */ ILIST gen_numlist(INTEGER minimum_value,UNSIGNED number_of_values) -(i,i) language c |
_gen_numlist.html | |
| /*
Fast polymorphic size-finding predicate, applicable to strings,
binaries, and lists
(of any type): */ UNSIGNED length(STRING) -(i) language c UNSIGNED length(BINARY) -(i) language c UNSIGNED length(ILIST) -(i) language c UNSIGNED length(RLIST) -(i) language c UNSIGNED length(BLIST) -(i) language c as "_length_2" UNSIGNED length(CLIST) -(i) language c as "_length_2" |
_length_0.html _length_1.html _length_2.html _length_3.html |
|
| /* Polymorphic "Last member of a List"
predicate: */ INTEGER lastmember(ILIST) -(i) language c %_lastmember_0 REAL lastmember(RLIST) -(i) language c %_lastmember_1 STRING lastmember(SLIST) -(i) language c as "_lastmember_0" % PNT lastmember(PNTLIST) -(i) language c as "_lastmember_0" (etc.) /* or: GLOBAL DOMAINS MYLIST = any_element_you_like* GLOBAL PREDICATES MYLIST my_last_member(MYLIST) -(i) language c as "_lastmember_0" */ |
_lastmember.html | |
| /*
Reverse-direction
Character Search (in a string or a binary). The 4-argument variants
start searching from a given initial position. The 5-argument variants
use additionally a "character table index", to search for a character
that "translates" to a given value (in the table), instead of finding
the character itself: */ STRING searchch_rev(STRING,CHAR ch,UNSIGNED posx) -(i,i,o) language c as "_searchch_rev_0" STRING searchch_rev(STRING,CHAR ch,UNSIGNED inpos,UNSIGNED posx) -(i,i,i,o) language c as "_searchch_rev_1" STRING searchch_rev(STRING,CHAR ch,UNSIGNED inpos,INTEGER casetb,UNSIGNED px) -(i,i,i,i,o) language c as "_searchch_rev_2" STRING searchch_rev(BINARY,CHAR ch,UNSIGNED posx) -(i,i,o) language c as "_searchch_rev_3" STRING searchch_rev(BINARY,CHAR ch,UNSIGNED inpos,UNSIGNED posx) -(i,i,i,o) language c as "_searchch_rev_4" STRING searchch_rev(BINARY,CHAR ch,UNSIGNED inpos,INTEGER casetb,UNSIGNED px) -(i,i,i,i,o) language c as "_searchch_rev_5" |
searchch_rev_asm.html | |
| /*
NON-DETERMINISTIC
UNIVERSAL SEARCH
PREDICATES, finding all
possible solutions
to search
problems, for a variety
of different argument/domains. */ Notes:
nondeterm STRING nd_search(STRING,STRING substr,UNSIGNED posX) -(i,i,o) language c %_nd_search_1 nondeterm STRING nd_search(BINARY,CHAR ch,UNSIGNED posX) -(i,i,o) language c %_nd_search_2 nondeterm STRING nd_search(BINARY,STRING substr,UNSIGNED posX) -(i,i,o) language c %_nd_search_3 nondeterm STRING nd_search(BINARY,BINARY subbin,UNSIGNED posX) -(i,i,o) language c %_nd_search_4 nondeterm STRING nd_search(STRING,CHAR ch,INTEGER inpos,UNSIGNED posX) -(i,i,i,o) language c %_nd_search_5 nondeterm STRING nd_search(STRING,STRING substr,INTEGER inpos,UNSIGNED posX) -(i,i,i,o) language c %_nd_search_6 nondeterm STRING nd_search(BINARY,CHAR ch,INTEGER inpos,UNSIGNED posX) -(i,i,i,o) language c %_nd_search_7 nondeterm STRING nd_search(BINARY,STRING substr,INTEGER inpos,UNSIGNED posX) -(i,i,i,o) language c %_nd_search_8 nondeterm STRING nd_search(BINARY,BINARY subbin,INTEGER inpos,UNSIGNED posX) -(i,i,i,o) language c %_nd_search_9 nondeterm STRING nd_search(STRING,CHAR ch,INTEGER inpos,INTEGER case,UNSIGNED pX) -(i,i,i,i,o) language c %_nd_search_10 nondeterm STRING nd_search(STRING,STRING substr,INTEGER inpos,INTEGER case,UNSIGNED pX) -(i,i,i,i,o) language c %_nd_search_11 nondeterm STRING nd_search(BINARY,CHAR ch,INTEGER inpos,INTEGER case,UNSIGNED pX) -(i,i,i,i,o) language c %_nd_search_12 nondeterm STRING nd_search(BINARY,STRING substr,INTEGER ipos,INTEGER case,UNSIGNED pX) -(i,i,i,i,o) language c %_nd_search_13 nondeterm STRING nd_search(BINARY,BINARY subbin,INTEGER ipos,INTEGER case,UNSIGNED pX) -(i,i,i,i,o) language c %_nd_search_14 |
_nd_search.html | |
| /*
Allocating, de-allocating, and manipulating 2- and 3-
dimensional Numeric Arrays, in
Visual Prolog's Heap: */ BINARY alloc_heaparray(UNSIGNED x,UNSIGNED y,UNSIGNED z) -(i,i,i) language c release_heaparray(BINARY array) -(i) language c release_heaparray(BINARY array,UNSIGNED new_array_size) -(i,i) language c set_heaparray(UNSIGNED x,UNSIGNED y,BINARY array,UNSIGNED value) -(i,i,i,i) language c set_heaparray(UNSIGNED x,UNSIGNED y,UNSIGNED z,BINARY array,UNSIGNED value) -(i,i,i,i,i) language c UNSIGNED get_heaparray(UNSIGNED x,UNSIGNED y,BINARY array) -(i,i,i) language c UNSIGNED get_heaparray(UNSIGNED x,UNSIGNED y,UNSIGNED z,BINARY array) -(i,i,i,i) language c add_heaparray(UNSIGNED x,UNSIGNED y,BINARY array,UNSIGNED increment_value) -(i,i,i,i) language c add_heaparray(UNSIGNED x,UNSIGNED y,UNSIGNED z,BINARY array,UNSIGNED inc_value) -(i,i,i,i,i) language c |
alloc_heaparray_asm.html | |
| /* Predicates calculating the sum of a
list of numbers (integers, unsigned integers, or reals): */ INTEGER il_sum(ILIST) -(i) language c UNSIGNED ul_sum(ULIST) -(i) language c as "_il_sum" REAL rl_sum(RLIST) -(i) language c |
_il_sum.html _rl_sum.html |
|
| /* TOURIST
SORT: An improved
descendant of "Radix Sort" and "Postman's Sort",
which is (to date, in 2004) the FASTEST SORTING ALGORITHM IN THE
WORLD: */ SLIST tourist_sort(SLIST string_list) -(i) language c UNSIGNED tourist_proc(BINARY array,UNSIGNED start_position,UNSIGNED num_records, UNSIGNED record_position,UNSIGNED record_width) -(i,i,i,i,i) language c Note: An early and restricted 16-bit implementation of this novelty algorithm is in http://www.omadeon.com/sourcecode/il_sort_asm.html |
tourist_sort_asm.html NOTE: The complete source code for "Tourist Sort" will not be published here. It is reserved for exclusive ownership by PDC, as a built-in predicate in future versions of Visual Prolog, after discussions (and a preliminary verbal agreement) with PDC's founder Leo Jensen. |
|
| /*
Reverse-direction String
Search. The second variant starts the search from an initial position
in the string: */ STRING searchstr_rev(STRING nstr,STRING substring,UNSIGNED substr_len) -(i,i,o) language c STRING searchstr_rev(STRING str,STRING substr,UNSIGNED inipos,UNSIGNED substrlen) -(i,i,i,o) language c |
searchstr_rev_asm.html | |
| /*
Comparing
strings. Optionally, "fuzzy comparison" using a "Character Table", which
specifies the translations of bytes to "acceptable values" (instead of
checking for simple equality): */ str_cmp(STRING str1,STRING str2) -(i,i) language c str_cmp(STRING str1,STRING str2,BINARY char_table) -(i,i,i) language c str_cmp(STRING str1,STRING str2,INTEGER chtable_index) -(i,i,i) language c |
str_cmp_asm.html | |
| /*
A family of "Character
Substitution Predicates", replacing massively all the occurrences
of 1 or 2
bytes (in a string or a binary) with a byte or a pair
of bytes:
*/ %_repl_ch.asm: repl_ch(STRING,CHAR old,CHAR new) -(i,i,i) language c repl_ch(BINARY,CHAR old,CHAR new) -(i,i,i) language c repl_ch(STRING,CHAR old,CHAR new,STRING output) -(i,i,i,o) language c repl_ch(BINARY,CHAR old,CHAR new,BINARY output) -(i,i,i,o) language c %repl_1c2.asm: UNSIGNED repl_1c2(STRING str,CHAR old,CHAR new1,CHAR new2,STRING out) -(i,i,i,i,o) language c UNSIGNED repl_1c2(BINARY bin,CHAR old,CHAR new1,CHAR new2,BINARY out) -(i,i,i,i,o) language c %repl_2c1.asm: UNSIGNED repl_2c1(STRING str,CHAR old1,CHAR old2,CHAR new) -(i,i,i,i) language c UNSIGNED repl_2c1(BINARY bin,CHAR old1,CHAR old2,CHAR new) -(i,i,i,i) language c UNSIGNED repl_2c1(STRING str,CHAR old1,CHAR old2,CHAR new,STRING out) -(i,i,i,i,o) language c UNSIGNED repl_2c1(BINARY bin,CHAR old1,CHAR old2,CHAR new,BINARY out) -(i,i,i,i,o) language c %repl_2c2.asm: UNSIGNED repl_2c2(STRING str,CHAR old1,CHAR old2,CHAR new1,CHAR new2) -(i,i,i,i,i) language c UNSIGNED repl_2c2(BINARY bin,CHAR old1,CHAR old2,CHAR new1,CHAR new2) -(i,i,i,i,i) language c |
repl_ch_asm.html repl_1c2_asm.html repl_2c1_asm.html repl_2c2_asm.html |
|
| /*
Ultra-fast exhaustive comparison
of all pairs of elements from two string-lists for
fast
Data Mining applications: */ compare_slists(SLIST slist1,SLIST slist2,BINARY b1,BINARY b2,BINARY cmpbin) -(i,i,i,i,i) language c % NOTE: This is a 'C' function, calling ASM-predicates from "alloc_heaparray.asm". |
compare_slists.c | |
| /*
A family of predicates
searching for two characters (in succession) inside a string or a
binary. The 5-argument variants start searching from an "initial
position. */ STRING search2ch(STRING str,CHAR ch1,CHAR ch2,UNSIGNED pos_found) -(i,i,i,o) language c STRING search2ch(BINARY bin,CHAR ch1,CHAR ch2,UNSIGNED pos_found) -(i,i,i,o) language c STRING search2ch(STRING str,CHAR ch1,CHAR ch2,UNSIGNED inputpos,UNSIGNED posx) -(i,i,i,i,o) language c STRING search2ch(BINARY bin,CHAR ch1,CHAR ch2,UNSIGNED inputpos,UNSIGNED posx) -(i,i,i,i,o) language c STRING search2chb(BINARY bin,CHAR ch1,CHAR ch2,UNSIGNED pos_found) -(i,i,i,o) language c STRING search2chb(BINARY bin,CHAR ch1,CHAR ch2,UNSIGNED inputpos,UNSIGNED posx) -(i,i,i,i,o) language c |
search2ch_asm.html | |
| /*
Fast list-length
extraction predicates; polymorphic, i.e. applicable to any (list or element) domains, since the elements
themseves do not play a part
in the counting process: */ listlen(ILIST,UNSIGNED) -(i,o) language c listlen(SLIST,UNSIGNED) -(i,o) language c listlen(CLIST,UNSIGNED) -(i,o) language c % "Polymorphic" examples of other list/element domains: listlen(ULIST,UNSIGNED) -(i,o) language c as "_listlen_0" listlen(SLL,UNSIGNED) -(i,o) language c as "_listlen_0" listlen(BLIST,UNSIGNED) -(i,o) language c as "_listlen_1" |
listlen_asm.html | |
| /* Extracting a part of a binary as a "sub-binary" (in a similar manner as extracting a
substring
of a given string). The resulting "sub-binary" is new, i.e. allocated in the
Stack. */ subbinary(BINARY in,UNSIGNED pos,UNSIGNED len,BINARY out) -(i,i,i,o) language c |
subbinary_asm.html |
|
| /* Non-deterministic 'repeat' and
loop-counter predicates
implemented in ASM:
*/ nondeterm repeat language c nondeterm repinc(INTEGER initval,INTEGER outval) -(i,o) language c nondeterm repinc(INTEGER initval,INTEGER maxv,INTEGER outval) -(i,i,o) language c nondeterm repinc(INTEGER initval,INTEGER maxv,INTEGER incr,INTEGER outval) -(i,i,i,o) language c nondeterm repdec(INTEGER initval,INTEGER outval) -(i,o) language c nondeterm repdec(INTEGER initval,INTEGER minv,INTEGER outval) -(i,i,o) language c nondeterm repdec(INTEGER initval,INTEGER minv,INTEGER incr,INTEGER outval) -(i,i,i,o) language c |
_repeat_asm.html _repinc_asm.html _repdec_asm.html |
|
| /* A Family of simple predicates
implementing counters for non-recursive
loops: */ ctr_set(INTEGER which_counter,INTEGER value) -(i,i) language c INTEGER ctr_inc(INTEGER which_counter) -(i) language c INTEGER ctr_dec(INTEGER which_counter) -(i) language c INTEGER ctr_get(INTEGER which_counter) -(i) language c lctr_set(INTEGER which,LONG value) -(i,i) language c INTEGER lctr_add(INTEGER which,INTEGER value) -(i,i) language c LONG lctr_inc(INTEGER which) -(i) language c LONG lctr_dec(INTEGER which) -(i) language c LONG lctr_add(INTEGER which,LONG value) -(i,i) language c LONG lctr_get(INTEGER which) -(i) language c |
ctr_c.html ctr_asm.html lctr_c.html lctr_asm.html |
|
| /* A
Family of predicates incrementing or decrementing "procedurally" all
the members of a list of numbers (changing their values without
regard for Prolog's "referential transparency"): */ %_il_inc.asm: il_inc(ILIST number_list) -(i) language c il_inc(ILIST number_list,INTEGER amount_to_add) -(i,i) language c %_il_dec.asm: il_dec(ILIST number_list) -(i) language c |
il_inc_asm.html il_dec_asm.html |
|
| /* Optimized general-purpose memory-copying predicate: */ memcopy(STRING source,INTEGER sourcePos,STRING dest,INTEGER destPos,UNSIGNED size) -(i,i,i,i,i) language c % Polymorphic versions, re-using the same code but requiring different Global Declarations: memcopy_bb(BINARY source,INTEGER sourcePos,BINARY dest,INTEGER destPos,UNSIGNED size) -(i,i,i,i,i) language c as "_memcopy" memcopy_bs(BINARY source,INTEGER sourcePos,STRING dest,INTEGER destPos,UNSIGNED size) -(i,i,i,i,i) language c as "_memcopy" memcopy_sb(STRING source,INTEGER sourcePos,BINARY dest,INTEGER destPos,UNSIGNED size) -(i,i,i,i,i) language c as "_memcopy" |
memcopy_asm.html | |
| /* Fast Reverse-of-a-List predicates,
for multiple list-domains: */ ILIST listrev(ILIST) -(i) language c SLIST listrev(SLIST) -(i) language c listrev(ILIST,ILIST) -(i,o) language c listrev(SLIST,SLIST) -(i,o) language c % NOTE: The 'SLIST' output arguments are created by fresh allocation of memory in the stack. The variants with only one argument perform "procedural" changes inside the list, without regard to Prolog's "referential transparency". % Polymorphic versions, re-using the same code but requiring different Global Declarations: MYLIST listrev(MYLIST) -(i) language c listrev(MYLIST,MYLIST) -(i,o) language c % (where 'MYLIST' is any user-defined list domain) |
list_rev_asm.html | |
| /* Deleting successive duplicate characters, in
strings or binaries: */ UNSIGNED del_dupch(STRING string,CHAR ch) -(i,i) language c UNSIGNED del_dupch(BINARY bin,CHAR ch) -(i,i) language c STRING del_dupch(STRING string) -(i) language c BINARY del_dupch(BINARY bin) -(i) language c % NOTE: The 2-argument versions delete duplicates of a specific (given) character. |
del_dupch_asm.html | |
| /* Deleting an element from a list, or
NON-DETERMINISTICALLY generating a
deleted element and/or generating a new
list without the deleted
element: */ del_element(INTEGER,ILIST) -(i,i) language c del_element(STRING,SLIST) -(i,i) language c del_element(CHAR,CLIST) -(i,i) language c del_element(INTEGER,ILIST,ILIST) -(i,i,o) language c del_element(STRING,SLIST,SLIST) -(i,i,o) language c del_element(CHAR,CLIST,CLIST) -(i,i,o) language c INTEGER del_element(ILIST,UNSIGNED) -(i,i) language c STRING del_element(SLIST,UNSIGNED) -(i,i) language c CHAR del_element(CLIST,UNSIGNED) -(i,i) language c % Polymorphic versions, re-using the same code but requiring different Global Declarations: del_element(WSFLAG,WSFLAGS,WSFLAGS) -(i,i,o) language c as "_del_element_3" % etc. |
del_element.asm | |
| /* Direct (faster) replacements
for Visual Prolog's built-in "searchstring/3".
The 4-argument variant also takes an initial position. The 5-argument
variant also takes a "character table" input, to search with
"generalised case-insensitivity": */ STRING searchstr(STRING text,STRING substring,UNSIGNED position) -(i,i,o) language c STRING searchstr(STRING input,STRING substr,UNSIGNED inPos,UNSIGNED positionx) -(i,i,i,o) language c STRING searchstr(STRING input,STRING substr,UNSIGNED inPos,INTEGER case,UNSIGNED posx) -(i,i,i,i,o) language c % NOTE: These predicates are more efficient than "nd_search", if non-determinism is not required. |
searchstr_asm.html | |
| /*
Setting / getting Q-word (64-bit) elements from a binary, and better
replacements for 'setwordentry' and 'setdwordentry': *. UNSIGNED setword(BINARY b,UNSIGNED pos,SHORT val) -(i,i,i) language c UNSIGNED setdword(BINARY b,UNSIGNED pos,INTEGER val) -(i,i,i) language c UNSIGNED setqword(BINARY b,UNSIGNED pos,REAL val) -(i,i,i) language c SHORT getword(BINARY b,UNSIGNED pos) -(i,i) language c INTEGER getdword(BINARY b,UNSIGNED pos) -(i,i) language c REAL getqword(BINARY b,UNSIGNED pos) -(i,i) language c |
setword_asm.html setdword_asm.html setqword_asm.html |
|
The following notice should be left intact when re-distributing this document (either in printed or in electronic form): "32-bit Assembly Language Extensions for Visual Prolog" http://www.omadeon.com/asm See also: The G.I.S. Prolog Interpreter (a descendant of PDC's "P.I.E. engine") |
||
| Author:
George A. Stathis © 2005-2007 Author's URL: http://www.omadeon.com Author's e-mail: omadeon@hotmail.com |
COPYRIGHT
NOTICE: All the source-code in this library is free for use in any application, provided the author's copyright is mentioned. Exarchou & Nikolopoulos Consulting Engineers Overseas Ltd 62-64 Grammou Street, GR-15124 Marousi, Athens, Greece Tel +30 210 8052501 to -503 Fax +30 210 8066571 Email: mail@enb.gr Web: http://www.enb.gr |
|