flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > BASELIB: General purpose libs for beginners Goto page Previous 1, 2, 3, 4, 5, 6, 7 |
Author |
|
fasmnewbie 06 Oct 2017, 18:16
I just finished creating a minimal "sbase32w.asm" version of Win32 BASELIB source. Well this one is a very basic version (but working), missing many other functions of the original "sbase32w.asm".
Major difference: This one is developed by using high-level features of FASMW (proc, invoke, stdcall, .if etc). I don't personally like it due to its high-level nature... but I think ignoring FASM's high-level features completely is not 'productive' either. Some day, you'd be required to come up with Line of Code (LOC) "costing" and knowing some of the high-level features would come handy. But contrary to popular belief, ASM high-level features are actually NOT for beginners no matter how friendly they look. High features are for those who already appreciated how they work at the low-level layer. If you prefer the low-level, just download BASELIB at the first post. Good luck with this one. Correct the bugs yourself p/s "bkernel.asm" can be downloaded from "core.zip" on post#1 Last edited by fasmnewbie on 14 Dec 2017, 09:55; edited 18 times in total |
|||
06 Oct 2017, 18:16 |
|
Tomasz Grysztar 06 Oct 2017, 18:30
fasmnewbie wrote: But contrary to popular belief, ASM high-level features are actually NOT for beginners no matter how friendly they look. High features are for those who already appreciated how they work at the low-level layer. If you prefer the low-level, just download BASELIB at the first post. |
|||
06 Oct 2017, 18:30 |
|
fasmnewbie 13 Oct 2017, 18:28
Thanks for the support Tomasz. I can see similar trend from the likes of MASM when they dropped some of the high-level features which were once crucial in 32-bit ML. Like "invoke" and .IF/.ENDIF. Microsoft decided to back to the low-level approach.
|
|||
13 Oct 2017, 18:28 |
|
fasmnewbie 13 Oct 2017, 18:31
Just added a new Win64 source file (core64.asm). This source is an equivalent of BASELIB's "base64w.asm", targetted for Win64. The source is in FASM syntax only. File is added in "core.zip" on Page 1.
The differences from "base64w.asm": 1. Partially ABI compliance. 2. Rely only on kernel32 as the main external. 3. Most of the routines now are callable from high-level languages, except those requiring XMM returns and arguments. (This is a future project, if I have time) 4. Routine changes: Added ---------- mem_alloc2 mem_free2 dble2str file_delete Discarded ---------- memview2 memviewb prnbinf prndblr prnfltr Warning: Still quite ugly and could be buggy. "base64w.asm" and "core64.asm" although similar in functions, are not compatible with each other. Linux64 version is on the horizon. Can't promise that soon, anyway |
|||
13 Oct 2017, 18:31 |
|
fasmnewbie 16 Oct 2017, 13:29
Updated the "bkernel.asm" above. Just finished with "fpu_stack".
Bug report: I think FASM's proc32 or stdcall scratches EDX when called/used from within a function and addressing local data via "ADDR" operator. Using the library provided above, here's how the issue emerges (observe dumpreg output of EDX); Code: format PE console include 'win32axp.inc' entry main section '.data' data readable writeable h db 'hello world',0ah,0 section '.text' code readable executable main: call foo ;mov edx,-13 ;call dumpreg ;stdcall prnstrz,h ;these, do not ;call dumpreg call halt call exitx ;-------------------------- proc foo locals h db 'Hello World',0ah,0 endl mov edx,10h call dumpreg stdcall prnstrz,addr h ;this clobbers edx ;lea edi,[h] ;stdcall prnstrz,edi ;these do not call dumpreg ret endp |
|||
16 Oct 2017, 13:29 |
|
Tomasz Grysztar 16 Oct 2017, 13:50
See Windows header documentation, section 2.1:
Quote: If the parameter is preceded by the addr word, it means that this value is an address and this address should be passed to procedure, even if it cannot be done directly - like in the case of local variables, which have addresses relative to EBP/RBP register. In 32-bit case the EDX register is used temporarily to calculate the value of address and pass it to the procedure. |
|||
16 Oct 2017, 13:50 |
|
fasmnewbie 16 Oct 2017, 13:57
Ok, got it.
Thought it was a bug. |
|||
16 Oct 2017, 13:57 |
|
fasmnewbie 16 Oct 2017, 14:20
I re-uploaded the "bkernel.asm" above to demonstrate the use of "DUP(x)" inside a LOCALS...ENDL instead of plain "RB" (reserve byte). Already has a lot of RB in there, but no DUP. If you know any other high-level features that can be included, do modify and share. Thanks.
|
|||
16 Oct 2017, 14:20 |
|
fasmnewbie 23 Oct 2017, 21:36
Using bkernel.asm above or any other BASELIB library, here's one simple demo to learn / teach FPU instruction in a more interactive and efficient manner without going back and forth the debugger.
Code: format PE console include 'win32axp.inc' entry main section '.data' data readable writeable msg db 'hello world',0ah,0 section '.text' code readable executable main: ;reset FPU precision, or finit ;stdcall fpu_precision,1 fldpi ;load to ST1 fchs ;change sign fld1 ;load to ST0 call fpu_stack ;see initial FPU stack call prnline ;visual separator fsub st0,st1 ;learn FSUB instruction call fpu_stack ;see the result call halt call exitx The output from "fpu_stack" after executing FPU's FSUB instruction; Code: st0|+1.000000000000000000 st1|-3.141592653589793238 st2| ... st3| ... st4| ... st5| ... st6| ... st7| ... st0|+4.141592653589793238 st1|-3.141592653589793238 st2| ... st3| ... st4| ... st5| ... st6| ... st7| ... Just be reminded that "bkernel.asm" is highly experimental - my first attempt to include as many high-level features of FASMW as possible. If in doubt, just use the much stable BASELIB library. |
|||
23 Oct 2017, 21:36 |
|
fasmnewbie 23 Oct 2017, 23:34
Now that all the basic modules are available, you can extend them by building some nice macros on top of it. Below is a demo of creating 2 macro extensions from "bkernel.asm" or any other BASELIB sources.
Code: format PE console include 'win32axp.inc' entry main macro strline a,b { stdcall prnstrz,a if ~b eq repeat b call prnline end repeat end if } macro binary [a] { forward stdcall prnbinb,a strline '=' strline `a,1 } section '.data' data readable writeable msg db '2 new lines',0 section '.text' code readable executable main: strline msg,2 strline "Demo: Binary Arithmetics & Logical Operations" call prnline binary eax,EBX,ecx ;use the macro or eax,ebx ;Practice using OR call prnline binary ebx,EaX call halt call exitx The output shows two named registers are placed tight to each other after performing an OR bitwise operation on them using "binary" macros built on top of "prnbinb" routine. Code: 2 new lines Demo: Binary Arithmetics & Logical Operations 01110101 11000100 11101111 00001010=eax 00000000 00000000 00000000 00110001=EBX 00000000 00000000 00000000 00000000=ecx 00000000 00000000 00000000 00110001=ebx 01110101 11000100 11101111 00111011=EaX |
|||
23 Oct 2017, 23:34 |
|
fasmnewbie 24 Oct 2017, 00:11
Another more focused example, this time using bitwise AND on EAX and EBX registers
Code: format PE console include 'win32axp.inc' entry main macro strline a,b { stdcall prnstrz,a if ~b eq repeat b call prnline end repeat end if } macro binary [a] { forward stdcall prnbinb,a strline '=' strline `a,1 } section '.text' code readable executable main: strline "Bitwise AND EAX(345),EBX(102)",2 mov eax,345 mov ebx,102 binary EAX,EBX ;See initial bits and eax,ebx ;Practice AND bitwise strline "-----------------------------------",1 binary EAX ;see bit changes after AND call halt call exitx Output Code: Bitwise AND EAX(345),EBX(102) 00000000 00000000 00000001 01011001=EAX 00000000 00000000 00000000 00110001=EBX ----------------------------------- 00000000 00000000 00000000 00010001=EAX Hope you like it |
|||
24 Oct 2017, 00:11 |
|
fasmnewbie 03 Dec 2017, 04:16
I forgot to mention how to access CPULIB from, say C. Here's a little example;
Code: // DEMO: Importing from CPULIB 64-bit binaries // gcc -m64 this.c cpu64.o -o this (Linux64) // or // gcc -m64 this.c cpu64.dll -o this.exe (Win64) #include <stdio.h> #define MAX 100 //Refer to the supplied Documentation (cpudoc) extern void dumpreg(void); //both void extern void dumpxmm(unsigned long long); //one int argument extern unsigned long long randm(unsigned long long); extern void str_token(char *,char *); //two C-string arguments extern void memview(unsigned long long *,unsigned long long); int main() { unsigned long long x=0; char tok[]="/? ."; char str[]="/Hello??. / .World... how?are/you"; unsigned long long *p = &x; dumpxmm(10); //view output in hex for (x; x <= MAX ; x++) printf("%llu ",randm(MAX)); putchar('\n'); str_token(str,tok); putchar('\n'); memview(p,50); dumpreg(); return 0; } Here's the output from Linux64 Code: XMM0 : 0|FF00 XMM1 : 2F2F2F2F2F2F2F2F|2F2F2F2F2F2F2F2F XMM2 : 0|0 XMM3 : 0|FF000000000000 XMM4 : 7465675F6F736476|5F5F00656D697474 XMM5 : 0|0 XMM6 : 0|0 XMM7 : 0|0 XMM8 : 0|0 XMM9 : 0|0 XMM10: 0|0 XMM11: 0|0 XMM12: 0|0 XMM13: 0|0 XMM14: 0|0 XMM15: 0|0 65 35 94 79 63 53 42 39 90 21 28 57 16 22 85 51 30 83 63 18 54 53 100 72 74 22 13 78 16 80 62 46 82 84 42 74 41 52 69 45 60 2 98 89 32 94 49 14 63 36 60 22 10 55 70 54 72 18 55 16 80 71 28 72 41 90 3 11 58 6 60 52 52 30 41 7 59 54 14 87 50 94 54 51 27 5 66 28 53 20 62 58 94 46 33 61 77 61 73 91 56 Hello World how are you 0000000000000065 |00007FFF20D82DE0| 0|0 00007FFF20D82DE0 |00007FFF20D82DE8| 8|8 000000002E203F2F |00007FFF20D82DF0| 10|16 0000000000406A1D |00007FFF20D82DF8| 18|24 3F3F6F6C6C65482F |00007FFF20D82E00| 20|32 726F572E202F202E |00007FFF20D82E08| 28|40 646C |00007FFF20D82E10| 30|48 RAX|00007FFF20D82DE0 RBX|0000000000000000 RCX|00007F94A663A290 RDX|000000000000000A RSI|0000000000000032 RDI|00007FFF20D82DE0 R8 |00007F94A6909780 R9 |00007F94A6B3D700 R10|00000000000001D6 R11|0000000000000246 R12|00000000004004E0 R13|00007FFF20D82F10 R14|0000000000000000 R15|0000000000000000 RBP|00007FFF20D82E30 RSP|00007FFF20D82DE0 RIP|00000000004006BC [UHEX] Note that not all CPULIB modules are suitable for high-level access. CPULIB attachment is in the first post. |
|||
03 Dec 2017, 04:16 |
|
fasmnewbie 30 Jan 2018, 03:05
I updated BASELIB to Revision 2.9 due to small bugs popping up here and there in "bkernel.asm" source.
|
|||
30 Jan 2018, 03:05 |
|
fasmnewbie 12 Feb 2018, 10:17
Updated to Revision 3.0. This is a major and milestone update. With LOTS of bug fixes (fatal and non-fatal). Note that the attachment included in the first post is FASM-only attachments to reduce the load.
For other syntaxes and other things, the full load of BASELIB/CPULIB can be downloaded from Sourceforge or my Google+. Thanks to those who reported the bugs. |
|||
12 Feb 2018, 10:17 |
|
fasmnewbie 15 Feb 2018, 20:02
A small update and bug fixes to Revision 3.1 that doesn't affect the main source (it was a small bug in "bkernel.asm").
Please note that this is FASM-only attachments. For other syntax (NASM, MASM), you can download the full version of BASELIB/CPULIB from Sourceforge or my Google+ profile. |
|||
15 Feb 2018, 20:02 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.