News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Help needed to build a library of PROCs

Started by frktons, January 10, 2013, 12:38:32 PM

Previous topic - Next topic

frktons

I need to organize the routines I'm coding, and others I've already coded,
in a rational way in order to be able to use them without a lot of
hassle, in my programs or in other PROCs.

The last time I did something of this kind was about 25 years ago
with a different progam language, so I need some advice on how
to build the routines in the correct way, ready to be "stored" inside
a library, and used when needed.

Many of you have far more experience and knowledge about assembly
than I could ever achieve at my age, and so who can I ask for advice?
Yes you guessed it.  :biggrin:

Let's start with the first PROC, and proceed step by step until it is
ready to be put in a library and used from there.

I recently coded the routine to format dword unsigned integer numbers
with localized thousand separator and leading spaces in order to have a
right aligned fixed lenght string.

First things first.

1) I'd define the PROC in this way:
FormatDW PROTO Num:DWORD, FormattedStr:DWORD, LenFmt:DWORD

because I want to use the PROC passing it the number to format, the pointer to the
returned string and the lenght of the string to be returned, like:
INVOKE FormatDW,Num2Format,  PtrStr, 7

2) Because the PROC uses localized data that I get with an API, and two more PROCs
to fill 2 supporting arrays, is it better to leave them outside the FormatDW PROC, or
making them part of the same routine? 

I think this is enough for the first post.

I hope your suggestions, examples, and personal coding styles will help me to find a
good way to organize the coded/coding stuff.  :t

Frank
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

first, you can build and manage a static library using LIB.EXE
which is a stub that actually runs LINK.EXE
so - you can do it just by using LINK
add - subtract - replace - list - OBJ modules

if you have such a library....
the routines that are referenced get "pulled" into (linked with) the EXE you are building
so - if one module references another - that module gets pulled in automatically

but - things are linked on a per-module basis
if you reference one symbol in a module, the entire module gets linked

creating several smaller modules may make for a larger library, but a smaller EXE, in the end
that's because each object module contains a certain amount of overhead info

frktons

Thanks Dave.

I'd like to create a static library. So what exactly I do?
Let's say I have a source module called FormatDW.asm.
Does it need to be declared in some particular way or the
bare PROC is good enough?
Next step, I don't have a lib for the time being, and let's
say I'd like to create a new one called MyLib.lib.
What do I do then?
Something like lib module add library? or what?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

hutch--

Frank,

Have a look at how the masm32 library is built, its done the right way. Important factors are granularity, put each procedure in its own module and you never get more than you need. If its going to get the guts bashed out of it, write it with no stack frame for a little more speed in some circumstances.

dedndave

http://www.masmforum.com/board/index.php?topic=15480.msg126841#msg126841

on that post is a very simple library
to see how it is build, just look at the batch file
it also has an INC file and an EXE that was built using the LIB

i think the same is true of Hutch's masm32 library - the batch file is in there, someplace   :P
you might also look at how Hutch does his INC files
notice the IF ELSE ENDIF at the very beginning and the very end of each INC

frktons

Quote from: hutch-- on January 10, 2013, 02:15:27 PM
Frank,

Have a look at how the masm32 library is built, its done the right way. Important factors are granularity, put each procedure in its own module and you never get more than you need. If its going to get the guts bashed out of it, write it with no stack frame for a little more speed in some circumstances.

Thanks Steve, Better to have a look at already existing libraries, you're right.  :t

Quote from: dedndave on January 10, 2013, 02:27:51 PM
http://www.masmforum.com/board/index.php?topic=15480.msg126841#msg126841

on that post is a very simple library
to see how it is build, just look at the batch file
it also has an INC file and an EXE that was built using the LIB

i think the same is true of Hutch's masm32 library - the batch file is in there, someplace   :P
you might also look at how Hutch does his INC files
notice the IF ELSE ENDIF at the very beginning and the very end of each INC

Ok Dave, I'll see it and try to understand some basical things that I miss.  ;)
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

you will find that it's very easy   :t

what Hutch said about organization...
notice how he put some of the data items in their own modules
that makes them "reusable", so to speak

one example of that is bintbl.asm

frktons

Quote from: dedndave on January 10, 2013, 02:36:58 PM
you will find that it's very easy   :t

what Hutch said about organization...
notice how he put some of the data items in their own modules
that makes them "reusable", so to speak

one example of that is bintbl.asm

Oh yes, I like them reusable. After I've seen all the passages
to create, insert, modify, delete modules from a static lib, then
it'll be easy. At the moment I don't know about anything  :icon_eek:

Another thing I'd like to understand, among the others, is if I can use
some sort of IDE/TOOL to manage the process, or I have to use the
command line LINK/LIB commands to undertake the task.
BAT files are one option, what about other options, if any?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

frktons

#8
Alex sent me these notes about the main operations involved.
I put them here as a reminder for the job I'm going to do.

Thanks Alex

Quote
First you should assemble all your .asm files to the OBJ files.
ML /C /COFF file.asm
(you will get file.obj)

Create library:
LINK /LIB objectfile1.obj objectfile2.obj /OUT:libraryname.lib

Delete objects from it:

LINK /LIB /REMOVE:objectfile1.obj libraryname.lib

List object modules in it

LIB /LIST libraryname.lib

Add objects:

LINK /LIB libraryname.lib object1.obj
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

i don't know of any graphical interface for it
although, it wouldn't be hard to create one
maybe it's because - you build it - you update it once in a while - you use it - lol
it's not as though you spend a lot of time managing the library

back in the old days, you had a different set of libraries for each of the 16-bit memory models
it might have been nice to have a GUI app for that   :P
we used a lot of conditional assembly and batch files to do it
but - the interface was a little different
you could do it on the command line, or type LIB and get a prompt for commands
newer versions don't use the +/- commands, i don't think

at the command prompt, type "LIB /?" - it will give you a list of available switches
i think they all work directly with LINK, as well - but are not listed with "LINK /?"
Microsoft (R) Library Manager Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: LIB [options] [files]

   options:

      /DEF[:filename]
      /ERRORREPORT:{NONE|PROMPT|QUEUE|SEND}
      /EXPORT:symbol
      /EXTRACT:membername
      /INCLUDE:symbol
      /LIBPATH:dir
      /LIST[:filename]
      /LTCG
      /MACHINE:{ARM|EBC|IA64|MIPS|MIPS16|MIPSFPU|MIPSFPU16|
                SH4|THUMB|X64|X86}
      /NAME:filename
      /NODEFAULTLIB[:library]
      /NOLOGO
      /OUT:filename
      /REMOVE:membername
      /SUBSYSTEM:{BOOT_APPLICATION|CONSOLE|EFI_APPLICATION|
                  EFI_BOOT_SERVICE_DRIVER|EFI_ROM|EFI_RUNTIME_DRIVER|
                  NATIVE|POSIX|WINDOWS|WINDOWSCE}[,#[.##]]
      /VERBOSE
      /WX[:NO]


in addition to what Alex mentioned, you can also "extract" a module to create an OBJ from a library module
batch files are a good way to go to save some typing

EDIT:
i see you can get the list from LINK with "LINK /LIB"

jj2007

Two hints:
- use JWasm for testing, ml for the release version. Building the MasmBasic lib takes 13 seconds with ML but only 6 with JWasm
- use the private key word for procs that serve only inside the module - saves a few bytes for the name and makes testing of the main proc easier.

frktons

Quote from: jj2007 on January 10, 2013, 05:20:24 PM
Two hints:
- use JWasm for testing, ml for the release version. Building the MasmBasic lib takes 13 seconds with ML but only 6 with JWasm
- use the private key word for procs that serve only inside the module - saves a few bytes for the name and makes testing of the main proc easier.

Hi Jochen, thanks for the hints. As you know I like very much
examples, so please add the syntax of jwasm to assemble
modules to be stored into a library, and the same for the use
of private.
2 small lines will save me about 1 hour searching.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

frktons

Quote from: dedndave on January 10, 2013, 03:49:39 PM
i don't know of any graphical interface for it
although, it wouldn't be hard to create one
maybe it's because - you build it - you update it once in a while - you use it - lol
it's not as though you spend a lot of time managing the library

I think that during the developement process of one or more libraries, you DO spend
time adding, updating, correcting bugs...
But you are right, it is not difficult to build an interface, I did it some decades ago.
I had to select the module and the operation to do, and the appropriate BAT file
would have done the remaining operations. Just to save some typing, you know.
To spare some dozens of coding hours I'd probably do it in PBasic.
I'm sure Jochen has done something to manage the MasmBasic library, in the latest
few years.  :P
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

i was thinking, if i wanted to do something along that line,
i might want it in the form of a right-click context shell extension

you right-click on a library, and get a set of operations to select from
same for an object file, with a smaller set of operations

frktons

Quote from: dedndave on January 11, 2013, 01:06:38 AM
i was thinking, if i wanted to do something along that line,
i might want it in the form of a right-click context shell extension

you right-click on a library, and get a set of operations to select from
same for an object file, with a smaller set of operations

ERROR #000 - Unable to perform requested task.  ::)
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama