flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next |
Author |
|
fasmnewbie 18 Jan 2016, 18:02
Jan 19th Update (version 1,0.12)
[+] added "isint" routine to check whether a floating point value is also an integer. [+] Added new information to the Doc on how to create a minimum working source without the need to write them all at once. |
|||
![]() |
|
TmX 19 Jan 2016, 01:53
Hi fasmnewbie,
A small suggestion. For convenience, maybe a zipped source format is preferable to copy pasting from PDF. ![]() |
|||
![]() |
|
idle 19 Jan 2016, 16:02
indeed, searching souls must be inspired, clean book does little motivation
|
|||
![]() |
|
fasmnewbie 31 Jan 2016, 23:41
I uploaded the second attachment (CORE.zip) containing all the source files that can be used immediately.
|
|||
![]() |
|
fasmnewbie 03 Feb 2016, 19:20
I didn't include this in the attachment but u can include this yourself with no problem. This simple routine demonstrates how u can use 'subtle' routines like chr_find to create other routines - to prove that assembly language is just as powerful as any HLL in terms of modularity and software reusability.
The routine below str_token tries to simulate the C's strtok, by using chr_find routine as its main processor engine (slow, but sure) ![]() Code: format PE64 console include 'win64axp.inc' ;practice here mov rbx,delimiter mov rax,thestring call str_token call exitp ;data goes here thestring db '--, a drunk ? trying to -? write..',0 delimiter db '-,. ?',0 output: Code: a drunk trying to write The routine; Code: ;------------------------------ ;str_token(2) ;Display tokens off a 0-ended string ;------------------------------ ;RBX : Addr of 0-ended delimiter string ;RAX : Addr of the string ;------------------------------ align 8 str_token: push rax push rcx push rdx push rsi mov rsi,rax mov rcx,1 .again: lodsb cmp al,0 je .done mov dl,al call chr_find ;main processor test rax,rax jnz .hit ;delimiter hit xor rcx,rcx mov al,dl call prnchr jmp .again .hit: test rcx,rcx jnz .again call newline add rcx,1 jmp .again .done: pop rsi pop rdx pop rcx pop rax ret For 32-bit and 16-bit versions, just replace the registers (RAX->EAX etc) |
|||
![]() |
|
fasmnewbie 15 Feb 2016, 04:17
Added basic file processing routines to 64-bit library(fnew, fopen, fread, fwrite, fclose and fsize). Nothing fancy. Revision 1.1.6
|
|||
![]() |
|
fasmnewbie 16 Feb 2016, 11:11
Added str_find routine to both 32 and 64 bit source. Return status in RAX.
Example: Code: format ELF64 executable 3 mov rbx,thekey mov rax,thestring call str_find call prnint ;Display return status call exit thestring db 'Find me if u can!',0 thekey db 'd me i',0 |
|||
![]() |
|
fasmnewbie 16 Feb 2016, 11:27
Routines "memview" and "stackview" are very useful if you want to see the content of a C's structs and what's hidden in there, particularly on Linux where everything is defined with C interface and assembly reference is scarce. For example, I used these two to figure out the data kept in struct timespec (for nanoseconds) and file size field from fstat.
Use with caution. |
|||
![]() |
|
fasmnewbie 18 Feb 2016, 07:38
I added prnstr32 routine to core32w.asm to allow prnstr to work properly on native 32-bit Win OSes. I've been testing the lib on 64-bit OS, so I might have missed some of the technical issues related to native Win32 OSes. So if you are on native 32-bit Win, use prnstr32 in place of prnstr to print string with size. If condition so requires, just delete prnstr routine and rename prnstr32 to prnstr.
Linux source and 64-bit version are not affected by this. |
|||
![]() |
|
fasmnewbie 21 Feb 2016, 11:30
Made lots of changes;
1. Got rid of routine redundancies 2. introduced "chr_shuffle" to shuffle a 0-ended string randomly. 3. aprnint, aprndbl... now takes 3rd argument so you can decide on your own separator to print the array (newline, space, etc) 4. rndigit now takes a slightly different role (return a small random integer instead of digit... up to 255). You can increase/decrease the max bound in the same routine. This is revision 1.1.10. |
|||
![]() |
|
fasmnewbie 26 Feb 2016, 12:59
Added str_append and str_appends, to enable 2 strings to be combined.
|
|||
![]() |
|
fasmnewbie 26 Feb 2016, 13:09
I wrote a small demo program to test the mem_alloc behaviour among other things. I can no longer test this on Linux because Win10 ate up my reFind/grub entries. So I hope u can help me test on Linux and other PCs since I am not quite convinced with this mem_alloc routines I am having (malloc for windows and sys_brk for Linux).
The code tries to copy a user-input list of doubles to a dynamic memory block allocated by mem_alloc and then sort them up before displaying them. I tested this using my DLL but it should also work on the naked version library downloadable on Page 1. Code: format PE64 console include 'win64axp.inc' ;include 'base6.inc' ;tested via DLL entry main SZE = 4096 section '.data' data readable writeable instr db 'input doubles, ''.'' to end: ',0ah,0 dblstr rb 40 section '.code' code readable executable main: mov rax,instr call prnstrz mov rax,SZE call mem_alloc ;request memory mov rsi,rax ;save block pointer xor rdx,rdx ;data count xor rdi,rdi ;index addressing .get: mov eax,'> ' ;get doubles call prnstreg mov rax,dblstr call readstrz cmp byte[dblstr],'.' ;sentinel je .done mov rax,dblstr call str2dbl add rdx,1 mov [rsi+rdi],rax ;save to dynamic mem add rdi,8 jmp .get .done: cmp rdx,0 je .exit mov rax,rsi mov rbx,rdx mov rcx,0 ;ascending call sort_dbl ;sort data mov rax,rsi mov rcx,'|' mov rbx,rdx call aprndbl ;display sorted array .exit: mov rax,rsi call mem_free ;free mem call exitp Output Code: input doubles, '.' to end: > 234.112 > -0.0 > 115.238 > -0.012 > 0.0 > 64.345 > . -0.012|-0.0|0.0|64.345|115.238|234.112| |
|||
![]() |
|
fasmnewbie 28 Feb 2016, 14:42
[Attachment moved to Page 1]
Last edited by fasmnewbie on 01 Mar 2016, 05:24; edited 1 time in total |
|||
![]() |
|
fasmnewbie 28 Feb 2016, 14:45
[Attachment moved to Page 1]
Last edited by fasmnewbie on 01 Mar 2016, 05:25; edited 1 time in total |
|||
![]() |
|
fasmnewbie 28 Feb 2016, 14:54
If you are in doubt on which one to use, pick the downloads on page 1. But at later stages, you might want to use the DLL and object versions, which offer better information hiding and much more convenience.
I think this is my final token. Thrown in everything I have. Not too good, but not too bad either. Not too fast, but not too slow too! LOL. But good enough for most beginners purposes. Hope you like it ![]() |
|||
![]() |
|
fasmnewbie 15 Mar 2016, 15:44
Corrected fatal bugs with the 32-bit versions/sources because I been ignoring them all these long to focus on 64-bit versions. LOL.
1. flt2int. replaced finit with multiple fstp because that would otherwise neutralize fpu_round (to set the rounding mode) result that should be called prior to calling flt2int. 2. powint. Forgot to include when the pow is 0. fixed 3. sincos. I don't know how the call to fpu_stack ended up somewhere in there. fixed 4. prnxmm / dumpxmm - delete option #9. 5. str_findz (all versions incl. 64-bit) now return the same result as str_find (location, instead of just status). If there's no more bugs, then take this as the final version/revision. |
|||
![]() |
|
fasmnewbie 16 Mar 2016, 08:56
Just uploaded the Linux 64-bit SO version (similar in concept to Win64 DLL just in case u don't know what it is).
Since Linux implementations may vary, do alert me if it behaves differently on your Linux. This SO was compiled with Mint 17. |
|||
![]() |
|
fasmnewbie 17 Mar 2016, 15:04
Apparently there's one very minor bug to str_findz. Fixed.
Name change: sort_chr to sort_byte to reflect the general idea of sorting not just ascii character array but also byte array. Just like always, if there's no more fatal bugs, this is the final revision. Sorry for the many corrections and updates. Good luck. |
|||
![]() |
|
fasmnewbie 19 Mar 2016, 14:25
While using this library, there are certain technical issues that you should be aware of;
1. All strings write are forward. If u attempt to write backward direction, and use one of the routine with CLD in it then you maybe in trouble. 2. Stack allocation for routines are not guaranteed to be empty (Try use stackview and you'll see that the stack frame content are not entirely empty). So FXSAVE data may land on one of these polluted area and be restored (FXRSTOR) with other 'residues' from the polluted area. I haven't encountered any problems so far but sh1t happens that could for example mess up with masking data. So my advice is that if u do need a guaranteed result, you need to alter all the routines with FXSAVE in it by clearing the data (use mem_reset) before calling FXSAVE. Like; Code: push rbp mov rbp,rsp sub rsp,528 ;declare more instead of just 512 and rsp,-16 ;align it first mov rbx,528 ;number of bytes to be cleared mov rax,rsp call mem_reset ;clear the memory fxsave [rsp] ;then use FXSAVE to place data in there ... ... fxrstor [rsp] mov rsp,rbp pop rbp ret 3. Routines support no AVX because my laptop don't have AVX. My work PCs do have them but I don't understand AVX anyway. But I may add them in the future xD |
|||
![]() |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.