flat assembler
Message board for the users of flat assembler.

flat assembler > Examples and Tutorials > BASELIB: General purpose libs for beginners

Goto page 1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
This is BASELIB, a set of general-purpose library intended for absolute beginners, each for linux and windows, that I hope can help newbies with their assembly programming at the earliest learning curve.

1. baselibs.zip - contains full source and binaries of BASELIB. For Win32/64 and Linux32/64. This also includes 16-bit versions as an unofficial release, just in case. Standalone. With documentation.

2. cpulib.zip - CPULIB. Partially ABI-compliant library. For Win32/64 and Linux32/64. Comes with full source and binaries. Not compatible with BASELIB. Standalone. With documentation.

Code:
LIST OF BASELIB ROUTINES Notes : The number in braces shows the # of arguments required : /Followed by the return value(s) (if applicable) : The list is for 64-bit versions only ------------------------------------------------------------------ Routines(190) Descriptions ------------------------------------------------------------------ prnreg(1) - Display register (hex) prnregd(1) - Display register (decimal) prnregdu(1) - Display register (unsigned decimal) dumpreg - Display register dump (hex) dumpregd - Display register dump (signed int) dumpregdu - Display register dump (unsigned int) dumpseg - Display segment registers dump (hex) stackview(1) - Display stack memview(2) - Display memory dump memviewc(2) - Display memory dump, emphasis on string mem_reset(2) - Reset memory content mem_set(3) - Fill up memory content mem_insertr(2) - Insert register content into memory mem_copy(3) - Copy memory block mem_load(1)/2 - Load a file to memory opcode(2) - Display encoding between 2 labels opsize(2)/1 - Get code size between 2 labels. flags(1) - Display RFLAG prnint(1) - Display signed integer prnintu(1) - Display unsigned integer prnhex(1) - Display hexadecimal prnhexu(1) - Display unsigned hexadecimal prnoct(2) - Display octal prnoctu(2) - Display unsigned octal prnbin(1) - Display signed binary prnbinu(1) - Display unsigned binary prnbinf(3) - Display formatted binary prnbinb(1) - Display binary with byte separators fpbin(1) - Display 64-bit Floating Point binary fpbind(1) - Display 32-bit Floating Point binary prndbl(1) - Display 64-bit precision value prndblr(1) - Display 64-bit precision value (rounded) prndble(2) - Display 64-bit precision with decimal places prndblx(1) - Display 80-bit precision value prnflt(1) - Display 32-bit float value prnfltr(1) - Display 32-bit float value (rounded) dblsplit(1)/2 - Split a real8 into parts fpdinfo(1) - Display Double binary information fpfinfo(1) - Display Float binary information dec2str(2) - Convert signed decimal to 0-ended string dec2stru(2) - Convert unsigned decimal to 0-ended string hex2str(2) - Convert signed hex to 0-ended string hex2stru(2) - Convert signed hex to 0-ended string bin2str(2) - Convert signed binary to 0-ended string bin2stru(2) - Convert unsigned binary to 0-ended string flt2str(2) - Convert a float to 0-ended string dbl2str(3) - Convert double to 0-ended string dblx2str(2) - Convert real-10 to 0-ended string readint/1 - Get an integer from kboard readdbl/1 - Get a double from kboard readflt/1 - Get a float from kboard fpu_stack - Display FPU stack fpu_sflag - Display FPU Status flag fpu_cflag - Display FPU Control flag fpu_tag - Display FPU Tag Word status fpu_reg(1) - Display one FPU register fpu_copy(1)/1 - Copy a FPU register fpu_precision(1)- Set FPU precision fpu_round(1) - Set FPU rounding control sse_round(1) - Set SSE rounding control sse_flags - Display SSE flags prnmmx(2) - Display one MMX register dumpmmx(1) - Display MMX dump prnxmm(2) - Display one XMM register dumpxmm(1) - Display XMM dump clearxmm - Clear all xmm registers prnymm(2) - Display one YMM register dumpymm(1) - Display YMM dump clearymm - Clear all ymm registers prnintd(2) - Display 32-bit integer prnintw(2) - Display 16-bit integer prnintb(2) - Display byte integer int2str(4) - Convert integer to string with multiple bases str2int(1)/1 - Convert 0-ended string to integer str2dbl(1)/1 - Convert 0-ended string to double str2flt(1)/1 - Contert 0-ended string to float dbl2int(1)/1 - Convert double to integer int2dbl(1)/1 - Convert integer to double isint(1)/1 - Check if an FP is a qualified integer rndint(1) - Generate 1 random integer randm(1)/1 - Get one unsigned random int randq(2)/1 - Generate unique random ints & save factorial(1)/1 - Get factorial powint(2)/1 - Calculate x ^ n (Integer) pow2(1)/1 - Calculate 2 ^ n (Integer) iseven(1)/1 - Check if a number is even isodd(1)/1 - Check if a number is odd bconv(2) - Convert & display from normal bases to other bases bitfield(3) - Extract bitfield of a given data addf(2)/1 - Floating Point ADD subf(2)/1 - Floating Point SUB mulf(2)/1 - Floating Point MUL divf(2)/1 - Floating Point DIV sqroot(1)/1 - Get square root fcalc(3)/1 - Two-operands floating point calculator rad2deg(1)/1 - Convert radian to degree deg2rad(1)/1 - Convert degree to radian sine(1)/1 - Get sine of a radian tangent(1)/1 - Get tangent of a radian cosine(1)/1 - Get cosine of a radian sincos(1)/2 - Get Sine and Cosine atangent(1)/1 - Get arc-tangent of a radian. lg10(1)/1 - Get a common log for a FP value ln10(1)/1 - Get a natural log for a FP value fpow(2)/1 - Calculate x ^ n (precision) chr_isdigit(1)/1- Check if a char byte is a digit chr_isalpha(1)/1- Check if a char is an alphabet chr_islower(1)/1- Check if a char is a lower case chr_isupper(1)/1- Check if a char is an upper case chr_change(3) - Change a char from a 0-ended string chr_chcase(1)/1 - Change a char's case chr_toupper(1)/1- Convert a char to uppercase chr_tolower(1)/1- Convert a char to lowercase chr_find(2)/1 - Find a char from a 0-ended string chr_count(2)/1 - Count a char from a 0-ended string ascii(1) - Simple ascii byte conversion chr_shuffle(1) - Shuffle a 0-ended string str_copy(3) - Copy a string to another string str_length(1)/1 - Find string length. str_cmpz(2)/1 - Compare 2 0-ended strings str_cmps(3)/1 - Compare 2 strings, with size str_toupper(1) - Up the case of a 0-ended string str_tolower(1) - Lower the case of a 0-ended string str_reverse(1) - Reverse a 0-ended string str_trim(2) - Trim a 0-ended string str_wordcnt(1)/1- Word count of a 0-ended string str_token(2) - Display tokens off a 0-ended string str_find(3)/1 - Find a sub-string from a 0-ended string str_findz(2)/1 - Find a sub-string from a 0-ended string str_append(5)/1 - Appends two 0-ended strings, with size str_appendz(4)/1- Appends two 0-ended strings sort_int(2) - Sort integer sort_byte(3) - Sort char/byte array sort_dbl(3) - Sort double sort_dblx(3) - Sort real10 sort_flt(3) - Sort integer digitprob(2)/1 - Extract digit from a signed integer digitprobu(2)/1 - Extract digit from an unsigned integer digithprob(2)/1 - Extract digit from a signed hex digithprobu(2)/1- Extract digit from an unsigned hex digitscan(2)/1 - Extract digit from a signed integer digitscanu(2)/1 - Extract digit from an unsigned integer digithscan(2)/1 - Extract digit from a signed hex digithscanu(2)/1- Extract digit from an unsigned hex digitcount(1)/1 - Extract digit from a signed integer digitcountu(1)/1 - Extract digit from an usigned integer digithcount(1)/1 - Extract digit from a signed hex digithcountu(1)/1- Extract digit from an umsigned hex aprnint(3) - Display array of signed integers aprnintu(3) - Display array of unsigned integers aprndbl(3) - Disp array of doubles aprnflt(3) - Dspl array of floats aprndblx(3) - Display array of real10 halt - Pause screen prnspace - Print a whitespace prnline - Print a new line prnspaces(1) - Print multiple whitespaces prnlines(1) - Print multipls lines prnchrp(2) - Display char pattern prnchrs(1) - Display a character from the stack prnchar(1) - Display a character variable prnstrd(2) - Display delimiter-ended string prnstreg(1) - Display short string off RAX readchr(1) - Get a character and save to variable ;----- OS SPECIFICS ----- prnchr(1) - Display char in AL prnstr(2) - Display string with size prnstrz(1) - Display 0-ended string readch/1 - Get a char from kboard. Return in AL readstr(1)/1 - Get a string with size mem_alloc(1)/1 - Get memory mem_free(1)/1 - Release memory timer_start - Start a timer timer_stop/1 - Stop a timer delay(1) - Delay execution in milliseconds get_ticks/1 - Get Ticks file_new(1) - Create a new file file_open(2) - Open a file with options for read or write file_read(3)/1 - Read from an opened file file_write(3)/1 - Write to an opened file file_close(1) - Close file handle file_size(1)/1 - Get file size file_copy(2) - Copy a file to a new file exitp - Pause before exit to system exit - Exit to system IMPORT TABLE (for win sources only)


(21.June.2018) Revision 3.4
[1] Bug fixes: "prnflt" and variants
[2] Bug fixes: "flt2str" and variants

You can also download the library directly from Google+ Profile
or download the latest directly from my drive which offers other syntax of BASELIB/CPULIB.
or from sourceforge


Description: BASELIB. Linux32/64 and Win32/64. Full sources and binaries.
Download
Filename: baselibs.zip
Filesize: 802.84 KB
Downloaded: 71 Time(s)

Description: CPULIB. Linux32/64 and Win32/64. Full sources and binaries. 64-bit version is partially compliant.
Download
Filename: cpulib.zip
Filesize: 615.7 KB
Downloaded: 65 Time(s)



Last edited by fasmnewbie on 06 Jul 2018, 07:37; edited 309 times in total
Post 03 May 2015, 05:33
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
Hello fasmnewbie,

thanks for your library; I am still working with it to become familiar with the very basic instructions and functions; it helped me understand some of the first few bits of this GiB-sized thing called 64bit-assembler.

Only 2 remarks:
1. The routines #56 (str_tolower) and #57 (str_alternate) do what they should, but not what I expected known from other languages: All chars except SPACE are modified by OR al,0x20. I think it should only work on letters (at least 7-bit-ASCII-letters; local differences (i. e. french, german) must be handled in an additional way).

2. Routine #18 (getchr): I don't know why it ends the program if ENTER is pressed to end the input. All I do is:
Code:
mov rcx,inputbuffer1 call getchr ; liest staendig Zeichen ein und gibt an Cursorposition aus, bis ENTER gedrueckt wird call newline ; Cursor links/rechts zum Navigieren in Eingabe; ESC oder Cursor hoch loescht Eingabe call newline call exitp inputbuffer1: db 1024 dup(0)


Is there somthing special to know about that getchr?
Post 04 May 2015, 10:44
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
= deleted =


Last edited by fasmnewbie on 02 Dec 2016, 16:26; edited 17 times in total
Post 04 May 2015, 16:24
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
I added the Windows DLL versions of the library (base6.zip and base3.zip)

This version also includes a template file (each) so that you can re-compile the DLL source in case you have made any changes.

Includes 4 sample files on how to access and use the library.


Last edited by fasmnewbie on 05 Apr 2016, 13:30; edited 9 times in total
Post 04 May 2015, 16:38
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
Hello fasmnewbie,

thanks for your detailed answer.

Yes, I am actually trying to work with Windows 8.1 64bit, straight from a long time with XP 32bit Smile
Those instructions after the 80286 are new to me, so it will become an interesting activity to make things work as I want them to (I hope there will still be enough time for me to learn all that is needed).

Your Routines #19 (getstr) and #20 (getstrz) work as expected and don't close the program. That's what I needed for the moment. Still there is some trouble with Cursor Up, but maybe that is because of the local keyboarddriver. I will handle that later.

I will test more of your Routines and give you a feedback. I am quite excited what awaits me with these mysterious xmm-Registers Smile
Post 04 May 2015, 17:15
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
Here I included the 32-bit library stack version for the sake of beginners who'd have to rely on other assembler source codes for 32-bit examples or to be used along with textbooks / reference that are using 32-bit code.

They are directly adapted from the register-based versions so you might expect some minor bugs in there. If you found none, then praise the lord xD


Last edited by fasmnewbie on 23 Mar 2016, 14:13; edited 8 times in total
Post 05 May 2015, 13:26
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
Just managed to get my hand on a Linux PC... so this is the Linux SO for 64-bit. I cut down the complicated steps in producing the SO so beginners don't have to play with gcc and other configuration headaches. Read the PDF file on how to access and where to place the library


Last edited by fasmnewbie on 05 Apr 2016, 13:31; edited 6 times in total
Post 05 May 2015, 13:31
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
Hello fasmnewbie,

thanks again for your examplecode.
To get a better overwiew I found these tables about the registers on wikipedia:
Image

Now it is more clear to me with what I can work.
(Somehow I conider this as the "fingers", with wich I will form the code.)

Still there are so many fundamentals/basics I have to get to know. So it might take some more days to get my very first real 64bit-assembler-program running (not only compiling examples and ready-to-use-sources).
What a luck FASM is available, Tomasz Grysztar is still active after all these years, and also this forum that's like a treasure chest, esp. for newcomers.
Post 05 May 2015, 16:32
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
remove post


Last edited by fasmnewbie on 22 May 2015, 04:57; edited 2 times in total
Post 05 May 2015, 18:55
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
80286

Good luck to you. There are a bunch of people on this board who can help you with that. Most of them are 5-star programmers (most are my gurus). Stay longer and you can identify who they are. NOT me though. I am quite hopeless in assembly and have the tendency to lose my index register somewhere in the middle. Hahaha!!
Post 05 May 2015, 19:11
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
Hello fasmnewbie,

I was just experimenting with doubles and singles and xmm0.

(Subnote: As I tried to code a subroutine for zeroing the doubles-buffer I remarked: There is no DS- and no ES-Register anymore - strange, if you usually used DS:SI and ES:DI for these lods/stos-things)

Using your routines #11 (prtdbl) and #12 (prntflt) for inputs 256.554 I got the outputs 256.5439999999999 and 256.5439
I suggest it could only be a fault in presentation because no operations on the values are made. But how could I get a more exact output if ever possible?

My complete code (except your routines) actually is:

Code:
format PE64 console include 'win64axp.inc' jmp codestart ;<place data here> align 64 string1: db 'Testtext#1',0 string2: db 'Danke für Ihre Eingabe!',0 inputbuffer1: db 1024 dup(0) align 64 doubles1: db 227 dup(0) ;<place code here> align 64 codestart: call zerodoubles1 ; Speicher fuer Doubles loeschen mov rcx,256.554 ; MUSS mit Dezimaltrennzeichen geschrieben werden, sonst falscher Wert! movq xmm0,rcx ; NO DIRECT IMMIDIATE call prtdbl call newline call newline call zerodoubles1; Speicher fuer Doubles loeschen mov ecx,256.5540 ; MUSS mit Dezimaltrennzeichen geschrieben werden, sonst falscher Wert! movd xmm0,ecx ; NO DIRECT IMMIDIATE call prtflt call newline call newline call exitp zerodoubles1: pushf push rax push rcx push rdi mov rdi,doubles1 sub al,al mov rcx,227 cld rep stosb pop rdi pop rcx pop rax popf ret


I don't know wether the zeroing-subroutine is working as it should; used to manage to handle a disassembler for those purposes.

edit:
Just saw your new lib and will have a look at it.
Post 05 May 2015, 19:16
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
post removed


Last edited by fasmnewbie on 28 May 2015, 14:32; edited 1 time in total
Post 05 May 2015, 20:03
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
Thanks again, fasmnewbie. I will heed your advices.
Post 05 May 2015, 20:28
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
post removed


Last edited by fasmnewbie on 28 May 2015, 14:33; edited 1 time in total
Post 05 May 2015, 20:32
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
remove post.
Post 13 May 2015, 15:04
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
post removed


Last edited by fasmnewbie on 26 May 2015, 21:30; edited 1 time in total
Post 23 May 2015, 12:58
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
1. I updated my comment in Post #1 to reflect the new update and notes.

2. Notes to beginners on align and unalign data while using SSE-related routines;

All SSE-based routines are unaligned because I intend to make those routines to be as flexible as possible in aligned and non-aligned situations.

To use aligned instructions (like movdqa, you need to explicitly align your data to be used by the SSE instructions, failure of which will give you segment fault error. Example;

Code:
format ELF64 executable 3 ;Linux example movdqa xmm3,dqword[x] ;aligned transfer instruction movdqa xmm1,dqword[y] ;aligned transfer instruction divps xmm1,xmm3 mov rax,8 ;option to display 4 packed singles. call dumpxmm ;dump xmm register in packed single format (rax=0). call exit align 16 ;---------> use align 16 x dd 34.557,0.034,-74.323,1.001 y dd 0.23,5.34,7.77,-3.023


Producing this output;
Code:
XMM0 : 0.0|0.0|0.0|0.0 XMM1 : -3.019980|-0.104543|157.0588|0.006655 XMM2 : 0.0|0.0|0.0|0.0 XMM3 : 1.001000|-74.32300|0.034000|34.55700 XMM4 : 0.0|0.0|0.0|0.0 XMM5 : 0.0|0.0|0.0|0.0 XMM6 : 0.0|0.0|0.0|0.0 XMM7 : 0.0|0.0|0.0|0.0 XMM8 : 0.0|0.0|0.0|0.0 XMM9 : 0.0|0.0|0.0|0.0 XMM10: 0.0|0.0|0.0|0.0 XMM11: 0.0|0.0|0.0|0.0 XMM12: 0.0|0.0|0.0|0.0 XMM13: 0.0|0.0|0.0|0.0 XMM14: 0.0|0.0|0.0|0.0 XMM15: 0.0|0.0|0.0|0.0


If you opted for un-aligned instruction, you can skip the "align 16" part as shown by another example below;

Code:
format PE64 console ;windows example include 'win64axp.inc' movdqu xmm1,dqword[x] ;unalign transfer movdqu xmm0,dqword[y] ;unalign transfer divpd xmm0,xmm1 mov rax,9 ;option to display as 2 packed doubles call dumpxmm call exitp x dq 34.557,0.034 ;align 16 is missing but recommended y dq 0.23,5.34


Which produces this output;

Code:
XMM0 : 157.0588235294117|0.006655670341754 XMM1 : 0.033999999999999|34.55700000000000 XMM2 : 0.0|0.0 XMM3 : 0.0|0.0 XMM4 : 0.0|0.0 XMM5 : 0.0|0.0 XMM6 : 0.0|0.0 XMM7 : 0.0|0.0 XMM8 : 0.0|0.0 XMM9 : 0.0|0.0 XMM10: 0.0|0.0 XMM11: 0.0|0.0 XMM12: 0.0|0.0 XMM13: 0.0|0.0 XMM14: 0.0|0.0 XMM15: 0.0|0.0


I hope these 2 examples can clear some confusions while using the supplied SSE-based routines.

Good luck.


Last edited by fasmnewbie on 17 Jun 2015, 00:41; edited 2 times in total
Post 26 May 2015, 20:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15859
Location: 162173 Ryugu
If you are concerned about performance then using unaligned transfers will hurt you. Even using MOVDQU on aligned data can hurt performance.
Post 27 May 2015, 00:31
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
revolution wrote:
If you are concerned about performance then using unaligned transfers will hurt you. Even using MOVDQU on aligned data can hurt performance.
Agreed. But for this lib, I just want to make things work first.

Off topic: Revo, if I remove my old posts / attachments, will it help reduce the site load or regain the site quota in some way? I see Haha doing it a lot.
Post 28 May 2015, 14:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15859
Location: 162173 Ryugu
fasmnewbie wrote:
Off topic: Revo, if I remove my old posts / attachments, will it help reduce the site load or regain the site quota in some way? I see Haha doing it a lot.
I'm not the one to ask because I don't have access to such things, but I suspect it makes very little difference.

I would request that you don't remove or destroy your old posts. It makes the board less useful and hard to follow. Some other people have deleted/destroyed old posts, but the reason was not to help improve the site.
Post 28 May 2015, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4, 5, 6, 7  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 2004-2018, Tomasz Grysztar.

Powered by rwasa.