flat assembler
Message board for the users of flat assembler.

Index > Main > Try for fasm standard library and standard macro library


Function naming style
proc MemCopy, pDest, pSource, Count
50%
 50%  [ 20 ]
proc Mem.Copy, pDest, pSource, Count
5%
 5%  [ 2 ]
proc memcopy, dest, source, count
17%
 17%  [ 7 ]
proc mem.copy, dest, source, count
20%
 20%  [ 8 ]
other, post your style
7%
 7%  [ 3 ]
Total Votes : 40

Author
Thread Post new topic Reply to topic
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
I have started making multi OS fasm libraries. Currently there's only few functions and they'r all for windows but i hope someone would write functions for linux and menuet also. I haven't tested the functions so please report errors.

I can't make it all by myself so i would be more than happy to get code from you guys(optimisations, menuet/linux versions, code for missing functions, etc..)

In the macro library there's new version of proc/invoke macros. Usage:
Code:
proc name[, arg1, arg2, ...]
[type frame/noframe, stdcall/cdecl]
[uses reg1, reg2, ...]
[var variable1] ; Works for frame and noframe types
[.variable1 dd ?] ; This works only with frame type.
begin
  return [val]
endp

[preserve reg1, reg2, ...] ; pushs and pops matching registers
invoke name[, arg1, arg2, ...] ; You can invoke your own functions and api functions with or without parameters
    


There's also macros that aren't written by me so if you find your macro there please say so so i can add your name there or if you don't want it to be there i will delete it..

I have one problem with the macro library: i have defined import macros in StdMacLib\Windows.inc and fasm is complaining:
Code:
.import
%fasminc%\StdMacLib\windows.inc [9] .import [3]:
     library \
%fasminc%\StdMacLib\windows.inc [95] library [3]:
       if ~ name#.needed
error: undefined symbol.
    

So if at the moment you have to include '%fasminc%\macro\import.inc' before your import section.. Any ideas how to fix this?

Simple example how to use these files:
Code:
format PE GUI 4.0
entry Start

OS fix Windows ; Use windows version of StdMacLib and StdLib

include '%fasminc%\stdmaclib.inc'

.code

proc foo
uses edx
begin
    mov edx, 100    
    return 2
endp

Start:
  preserve edx ; proc uses edx so invoke will push and pop edx
        invoke foo
  invoke ExitProcess, 0

.udata ; Uninitialised data section
    NotUsed dd ?

.idata ; Initialised data section
       NotUsed2 dd ?

.cdata ; Constant data section
 NotUsedStr db 'foobar',0

include '%fasminc%\macro\import.inc' ; How to fix this?!?
.import
    


And what about the structure macros there's on this board somewhere, should we start using them? And witch version of import/export macros should we use?
COMMENTS PLEASE!

It's 5:30 so i'm going to sleep.. Good night! =)

Tab size used to edit files below was equal to 2 spaces


Description: Updated 23.3.2004 21:15
Download
Filename: StdLib.zip
Filesize: 19.46 KB
Downloaded: 537 Time(s)



Last edited by aaro on 23 Mar 2004, 19:17; edited 10 times in total
Post 23 Feb 2004, 03:09
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Hi Aaro,
I must say that you've done quite impressive job Wink
I would like to help to development of FASM standard library, as I consider it as very important thing. I just hope I will have enough time :////

I think Privalov should tak a look at your macro library - we need to have one common macro library, the same for Fresh and FASM.

About the standard library itself:
First we should discuss how the code will look like. It's very important, it would be easier for user when whole library will have the same 'look'. What we have to discuss about:
1) the function categories:
- memory allocating
- string functions
- console i/o
- (more Smile)
2) names, and namespaces: there are many ways of naming our functions, I think that it would be the best way to name functions like: str.new, str.len, mem.alloc, mem.free, etc.
Another question is whether to use uppercase in names; I like names in lowercase, with '_', so I prefer "my_id" than "MyID".
3) we also have to discuss about some conventions, for example if our functions will look like:
Code:
proc mem.copy, source, dest, count
proc str.copy, source, dest    

or:
Code:
proc mem.copy, dest, source, count
proc str.copy, dest, source    

4) some conventions for commenting code - for example common header, it could look like:
Code:
;-----------------------------------
; MyLibraryName
; Short description of what MyLibrary does
;-----------------------------------
; copyright note, authors and contributors list
;-----------------------------------
    

And proably there are more topics that we have to discuss... of course all of the above are only my suggestions, but we have to agree to some coding scheme, as the FASM library will be quite big project, and it has to have common 'look and feel'.
Please write your opinions Wink

p.s. aaro, why did you started writing string library from scratch? In Fresh package there is already one lib for dynamic string handling.
Post 23 Feb 2004, 08:52
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
decard wrote:
Hi Aaro,
I must say that you've done quite impressive job Wink
I would like to help to development of FASM standard library, as I consider it as very important thing. I just hope I will have enough time :////

Thanks, and welcome to the team! Cool
Quote:

I think Privalov should tak a look at your macro library - we need to have one common macro library, the same for Fresh and FASM.

Yeah, it would be very nice
Quote:

1) the function categories:
- memory allocating
- string functions
- console i/o
- (more Smile)

I will add console i/o soon, thx for that and keep 'em coming
Quote:

2) names, and namespaces: there are many ways of naming our functions, I think that it would be the best way to name functions like: str.new, str.len, mem.alloc, mem.free, etc.
Another question is whether to use uppercase in names; I like names in lowercase, with '_', so I prefer "my_id" than "MyID".
3) we also have to discuss about some conventions, for example if our functions will look like:
Code:
proc mem.copy, source, dest, count
proc str.copy, source, dest    

or:
Code:
proc mem.copy, dest, source, count
proc str.copy, dest, source    


This is what i have used:
Code:
udata
  MemLib.Var1
enddata
proc MemCopy, pDest, pSource, Count
    

But i like your style for functions too.. I think we need to have poll.
Quote:

4) some conventions for commenting code - for example common header, it could look like:

I'll add something like that.
Quote:

p.s. aaro, why did you started writing string library from scratch? In Fresh package there is already one lib for dynamic string handling.

Didn't have anything better to do.. Wink
Seriously, if i remember correctly fresh strlib is using string handles that i think is unnecessary, but if fresh team gives me approval of using some of their functions i'll check those out.
Post 23 Feb 2004, 12:54
View user's profile Send private message Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
There's new version at the top, nothing big has changed. I just added copyright texts and names of those whose macros i have used in the macro library. And most importantly TODO file so if you want to help READ IT!

And seems like we'r going to stick to function naming allready used, but if you want to change it please vote! Voting will stop on next monday, then i'll change the poll to ask you for naming of library variables.

I also changed .code macro in windows.inc to include StdLib.asm automaticly.

Yeah, i know, i know.. There will be changes.log in the next release.. Wink
Post 24 Feb 2004, 02:46
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
aaro wrote:
Seriously, if i remember correctly fresh strlib is using string handles that i think is unnecessary, but if fresh team gives me approval of using some of their functions i'll check those out.

I'm in the Fresh team and I'm maintaining StrLib Wink Although Fresh StrLib uses string handles, its functions can work with string pointers as well. Actually you can just take this library and convert it that it would match your needs - just preserve the copytight note in the beggining of the source <-- that is the requirement of Fresh Artistic License Wink

regards
Post 24 Feb 2004, 13:44
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
First release that should actually work.. Wink

Added:
StdLibApi.txt
__% and %__ fixes
MemMove
MemFill
StrCat

Fixed:
proc macros

Code:
format PE GUI 4.0

OS fix Windows
include '%fasminc%\stdmaclib.inc'

.code

Start:
      invoke StrCat, sHello, sWorld
       push eax
    invoke StrRight, eax, 4
     push eax
    invoke MessageBox, 0, eax, eax, MB_OK
       call StrFree
        call StrFree
        
    invoke ExitProcess, 0

.cdata
sWorld           db 'World',0
sHello                db 'Hello',0

include '%fasminc%\macro\import.inc'

.end Start
    


decard:
Thanks for the info, but i don't think i want to convert the whole library.. What if i only take few functions from there what kind of text i should add then? Sorry i'm askind stupid guestions, but i'm connected thru gprs and it costs me 5,99€/MB so i'm not very willing to download anything.. Have 41€ bill allready and have used it just yesterday.. :´(


Last edited by aaro on 26 Feb 2004, 13:58; edited 1 time in total
Post 25 Feb 2004, 16:18
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
well then just write which functions you took from our StrLib and write who is an author (authors) of this functions. If you don't wan't to download whole Fresh package, here's the StrLib:

regards
Post 25 Feb 2004, 16:37
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
New version at the top:
Code:
Added:
StrCompCs
StrCopy
StrAlloc and StrFree      (Linux and Menuet)
.end macro (Windows.inc)
FileSetPos (Windows)

Changed:
StrAlloc and StrFree (Windows)
MemMove -> MemCopy

Fixed:
push and pop macros (Proc.inc)
StrMid

Updated:
proc macro to align procedures (Proc.inc)
StdLibApi.txt
TODO.txt
    

decard:
Thanks i'll have a look
Post 26 Feb 2004, 13:56
View user's profile Send private message Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
New version at the top:
Code:
Added:
pushd, pushw, pushf, pushfd, pusha, pushad, popd, popw, popf, popfd, popa and popad macros (Proc.inc)
StrRepeat
StrInsert
StrDelMid
StrReplaceAt
ConInit, ConUninit, ConRead, ConWrite (Windows)

Changed:
pop macro to pop in same order that fasm does (Proc.inc)
push and pop macros to check for argument size (Proc.inc)
invoke and proc macros to use pushd and popd (Proc.inc)

Updated:
TODO.txt
    
Post 01 Mar 2004, 17:11
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
At first glance, very nice! Wink
Post 01 Mar 2004, 18:20
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Code:
Added:
StrToNum
StrFromNum
enumflags (StdMacLib.inc)
stackcheck and endcheck (StdMacLib.inc)

Changed:
return and endp macros not to halt on push/pop miscount (Proc.inc)
    

Here's little example that demostrates power of StrToNum and StrFromNum:
Code:
format PE GUI 4.0

OS fix Windows
include '%fasminc%\stdmaclib.inc'

.code

Start:
   invoke StrToNum, sTestNum, 16
       invoke StrFromNum, eax, 16, STR_UPPER+STR_SIGNED;+STR_PREFIX
        push eax
    invoke MessageBox, 0, eax, eax, MB_OK
       call StrFree

    invoke ExitProcess, 0

.idata
sTestNum db '-0xFA09afh',0

include '%fasminc%\macro\import.inc'

.end Start
    

Tommy:
Thank you
Post 02 Mar 2004, 17:57
View user's profile Send private message Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng
Hi, Aaro:
Please see the belowing link:
http://board.flatassembler.net/topic.php?t=1151.

http://board.flatassembler.net/topic.php?t=1054
I supported some of new macros (proc/call/stdcall/ccall/import/export/library).
It can work on Win32/DOS platform and supported number ordinal APIs import/export. It maybe reference for you. Embarassed
Post 03 Mar 2004, 12:25
View user's profile Send private message MSN Messenger Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Code:
Added:
FileSetPos (Windows)
FileGetPos (Windows)
FileGetSize (Windows)
FileGetTime (Windows)
FileSetAttributes (Windows)
FileGetAttributes (Windows)
FileMove (Windows)

Changed:
FileDelete
FileClose

Updated:
StdLibApi.txt
TODO.txt
    


Kevin_Zheng:
Thanks, i'll have a look tomorrow when i get back home
Post 03 Mar 2004, 16:15
View user's profile Send private message Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Code:
Added:
ConFlush, ConSetPos, ConGetPos, ConSetColor, ConGetColor (Windows)
LF equ 13, 10 (Windows.inc)

Changed:
FileOpen (Windows)
FileSetAttributes -> FileSetAttribs
FileGetAttributes -> FileGetAttribs
var so now you can specify size of buffer allocated (Proc.inc)

Removed:
FileCreate (Windows)

Updated:
library, import and export macros with ones by Kevin_Zheng (Windows.inc)
FileRead (Windows)
FileSetPos (Windows)
StdLipApi.txt
TODO.txt
    

There's now 51 functions in the library if i counted them right!
Please give me more ideas for functions/libraries to add!
And even more happy news: jInuQ send me pm that he and gorshing are joining the StdLib team. jInuQ said that he's willing to start converting functions for Linux so we can finally start using this lib on other OSes than Windows as well. Any Menuet coders out there willing to help?

Kevin_Zheng:
I changed import, export and library macros to your versions. But there's still this issue to deal with:
Quote:

I have one problem with the macro library: i have defined import macros in StdMacLib\Windows.inc and fasm is complaining:

code:
.import
%fasminc%\StdMacLib\windows.inc [9] .import [3]:
library \
%fasminc%\StdMacLib\windows.inc [95] library [3]:
if ~ name#.needed
error: undefined symbol.



So if at the moment you have to include '%fasminc%\macro\import.inc' before your import section.. Any ideas how to fix this?

Would you have a look at this problem?
Post 11 Mar 2004, 14:30
View user's profile Send private message Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng
Hi, aaro:
Thank your work. Can you write a simple program for implementing your question? Please see the below link:
http://board.flatassembler.net/topic.php?p=7896#7896
Please see the demo file ord_dll in the package, I have tested it ok. And it maybe help you.
Thank you.
Post 16 Mar 2004, 05:59
View user's profile Send private message MSN Messenger Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro

    !!!!!!!!!!
    Combined StdMacLib with StdLib. Now to include this library you do it like this:
    "include '%fasminc%\StdLib.xxx.inc'" where xxx is OS you'r wanting code to be run(win,lnx,mnt)
    You can use "OUTPUT fix type" to change output file type. Types at the moment are:
    Windows:
    PE_GUI (default)
    PE_GUI_DLL
    PE_CONSOLE
    PE_CONSOLE_DLL
    Linux:
    ELF_EXECUTABLE (default)

    Added skeletons of all the libs for Linux and Menuet so if someone wants to start
    converting functions it should be somewhat easier now.
    !!!!!!!!!!

    Added:
    StrReverse
    .code, .idata, .udata, .cdata and .end macros for Linux and Menuet

    Changed:
    StrFromNum removed prefix option
    StrToFloat so now it converts numbers from any base and returns value in st0
    LF -> %lf
    ALL_PROCS -> PROC_INCLUDE_ALL
    Global variables aren't included if not used (ConLib.win.asm, MemLib.win.asm, Debug.inc)

    Updated:
    StdLibApi.txt
    StrToNum
    ConInit to check if it needs to allocate console (Windows)

Here's little example how to use it now on:
Code:
include '%fasminc%\stdlib.win.inc'

.idata
  Tmp     db 'FooBar',0

.udata
       hStr    dd ?

.code
Start:
     invoke ConInit
      invoke StrReverse, Tmp
      mov [hStr], eax 
    invoke ConWrite, eax, 0
     invoke ConRead, Tmp, 7
      invoke StrFree, [hStr]
      invoke ConUninit
    invoke ExitProcess, 0
       
.end Start
    

Kevin_Zheng:
Your macros are working now, i had to re-structure my whole package to get it working but it should be good now

All:
I'm planning to write StrFromFloat function and i'm thinking that it would be wisest to pass the floating point value in st0 so i don't have to write different versions of it for every float data type. What do you think? If you agree i'm going to extend my proc and invoke macros so it will be transparent to the coder calling the function(invoke will fld value automaticly).. I'm also going to add vararg type to procedures and pascal calling convention when i have enought time.

It's quite possible that there's bugs in the package because of the re-structuring so please report if you find any. Thanks.
Post 23 Mar 2004, 19:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.