Author Topic: BxbAsm  (Read 178857 times)

jcfuller

  • Guest
Re: BxbAsm
« Reply #165 on: April 20, 2012, 10:21:03 AM »
Steve,
  Yes but you can eliminate all the testing and adding of the function source by compiling each function to an object file and add them individually to a library. Then all you need to do is translate the function call from basic to asm syntax and link to the library. In this case only the functions used will be added to the exe.

James

SteveA

  • Guest
Re: BxbAsm
« Reply #166 on: April 20, 2012, 10:21:58 AM »
This is the list of commands for lcclib:

Quote
lcclib processes options in the order specified on the command line and in command files. If an option is repeated with different arguments, the last one to be processed takes precedence.

/VERBOSE
Displays details about the progress of the session. The information is sent to standard output and can be redirected to a file.
/LIST
Displays information about the output library to standard output. The output can be redirected to a file. You can use /LIST to determine the contents of an existing library without modifying it.
/OUT:filename
Overrides the default output filename. By default, the output library is created in the current directory, with the base name of the first library or object file on the command line and the extension .LIB.
/REMOVE:object
Omits the specified object from the output library. LCCLIB creates an output library by first combining all objects (whether in object files or libraries), and then deleting any objects specified with /REMOVE.


I just don't think it works quite the same as ar.

jcfuller

  • Guest
Re: BxbAsm
« Reply #167 on: April 20, 2012, 10:59:19 AM »
Steve,
From lcc.chm:

The lcclib Utility

The purpose of this utility is to build library files (.lib) from a list of object files. The general format of the command line is:

lcclib <options>  <library file>  <object files >


James

SteveA

  • Guest
Re: BxbAsm
« Reply #168 on: April 20, 2012, 12:19:54 PM »
The lcclib Utility
The purpose of this utility is to build library files (.lib) from a list of object files. The general format of the command line is:
lcclib <options>  <library file>  <object files >

Right, it builds library files, that's how I built bxblib.lib.
But, isn't that somehow different from what you are proposing and what you are doing with ar ?

I put all my source code in bxblib.c and bxblib.h and compile it as a .lib file.
It seems to me you are suggesting something else.

edit:
Q:
what is the advantage of compiling each function into an .obj and then (using ar or lcclib) adding each individual .obj to the lib ?
how does the result differ from simply compiling the source code for each function (at one time) and building a .lib ?

clearly I'm not grasping something here.
« Last Edit: April 20, 2012, 12:55:03 PM by SteveA »

jcfuller

  • Guest
Re: BxbAsm
« Reply #169 on: April 20, 2012, 01:08:50 PM »
Steve,
  As I mentioned earlier I did some testing with FreeBASIC in the past. It uses the MinGW linker ld.
I found that if I compiled a source with a number of functions to a library ALL the functions were added
to an exe that linked to the library even though I maybe only called one from my app.
But if I compiled each function to an object file then added each object file separately only the functions I actually called
were added to the exe.

Now maybe some linkers are smarter than others???

Try it with lcc and see what happens.

James

jcfuller

  • Guest
Re: BxbAsm
« Reply #170 on: April 20, 2012, 01:16:30 PM »
Steve,
  Also note how Hutch creates the Masmlib. He uses all individual asm files with just one function in each.

James

SteveA

  • Guest
Re: BxbAsm
« Reply #171 on: April 20, 2012, 01:33:17 PM »
Try it with lcc and see what happens.

I've been playing around with lcclib, making a .lib from .obj's.
I'm not used to using Lcclib from the commandline.
There is no IDE option for constructing .Libs this way.

I'm going test it in a moment to see if it's working the way we need.

jcfuller

  • Guest
Re: BxbAsm
« Reply #172 on: April 21, 2012, 05:38:43 AM »
Steve,
  For more info on static libraries take a look at the libraries topic in asmintro.chm from the Masm32 package.

James

SteveA

  • Guest
Re: BxbAsm
« Reply #173 on: April 21, 2012, 05:33:35 PM »
James,
It looks like making .Libs, from unrelated .Obj's, is going to be from the commandline.
I see no provision within Wedit for building .Libs from multiple .Objs.
That's why I originally thought it couldn't be done. And, I could not find any Wedit documentation regarding it.

I tried it, (lcclib) from the commandline and it does appear to work.
Hmm...,
now I need to figure out how I'm going to make all those functions into Obj's.

I do like the idea of doing it this way.
As you've noted, the way I designed the functions in Afunct.c, my original intention was to build the smallest possible Exe's.
And, as you've pointed out, a single .Lib file, created from a single .Obj file, does not always do that.

Steve

jcfuller

  • Guest
Re: BxbAsm
« Reply #174 on: April 22, 2012, 08:17:13 AM »
Steve,
  Probably the best way would be with a make file. I noticed Lcc has a make utility  but no info on how it's used.
I am most familiar with the gnu make and because I haven't used it lately I've forgotten most of what I learned.
I also don't have a "c" ide that I am comfortable with. I thought of using code::blocks but I can't seem to just compile to an object file.
All my c/c++ work has been mostly c++ using bcx to do the actual code generation.

The MinGW set up for RadAsm3 (my preferred ide) is borked so I think I'll spend the time trying to get it to work with just
MinGW gcc "c" files.

I thought about Geany but I had problems with it not deleteing temporary files. I use it on Linux and like it a lot.

James

jcfuller

  • Guest
Re: BxbAsm
« Reply #175 on: April 23, 2012, 07:58:16 AM »
Steve,
  Here is a gcc example of how to create a library using a make file.
James

c Files placed in their own directory:
cls.c
Code: [Select]
#include <windows.h>
void cls(void)
{
system("cls");
}
Locate.c
Code: [Select]
#include <windows.h>
void  locate(int cx, int cy)
{
    COORD coordScreen;
    HANDLE hConsole;


    coordScreen.X = cx;
    coordScreen.Y = cy;
                             /* Get this console handle */
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

                             /* Put the cursor at its coordinates */
    SetConsoleCursorPosition(hConsole, coordScreen);

}
color.c
Code: [Select]
#include <windows.h>
void color (int fg,int bg)
{

 HANDLE hConsole;
 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute (hConsole,fg+bg*16);

}
StrToFloat
Code: [Select]
#include <stdlib.h>
void  StrToFloat(char *NumStr, double *result)
{

    *result = atof(NumStr);

}
FloateToStr2
Code: [Select]
#include <string.h>
#include <windows.h>
void  FloatToStr2(double orgvalue, char *buffer)
{   char asciiValue[30];
    int len;


    gcvt(orgvalue, 80, buffer);       /* convert double to ascii */

    len = strlen(buffer);
    len--;

    if(buffer[len] == '.')
    {                             /* if this is an integer, get rid */
        buffer[len] = '\0';       /* of trailing decimal point. */
    }

    if(orgvalue >= 0)
    {
        strcpy(asciiValue, " ");       /* add leading blank space */
        strcat(asciiValue, buffer);
        strcpy(buffer, asciiValue);
    }
}
Value2Str.c
Code: [Select]
#include <stdio.h>
#include <string.h>
char *  value2strng(double value, char vartype)
{   static char buffer[81];
    int len, idx=0, dot=0;
    char ch, chx = vartype;
//    char ch, chx='#';
//    double value = 10;


    /* --- convert to ascii, here --- */
    sprintf(buffer, "% f", value);
    len = strlen(buffer);
    ch = buffer[idx];

    /* --- trim trailing zeros --- */
    if(chx == '#')                          /* Double: '#' */
    {
        idx = (len-1);
        ch = buffer[idx];

        while(ch == '0')
        {
            idx--;
            ch = buffer[idx];
        }
        buffer[(idx+1)] = '\0';
    }

    /* --- round up to .nn --- */
    else if(chx == '!')                     /* Single: '!' */
    {
        dot = (len-5);
        idx = (len-1);

        while(idx > dot)
        {
            if((buffer[idx] >= '5') && (buffer[(idx-1)] == '9'))
            {
                buffer[idx] = '\0';
            }
            else if(buffer[idx] >= '5')
            {
                buffer[(idx-1)]++;
                buffer[idx] = '\0';
            }
            else
            {
                buffer[idx] = '\0';
            }
            idx--;
        }
    }
    /* --- trim to dot --- */
    else                           /* Integers: '%' */
    {
        idx = (len-7);
        buffer[idx] = '\0';
    }

    return buffer;
}

The make file to compile and add all to a library.

Code: [Select]
AR = ar rcs
CC = gcc
OBJECTS = cls.o locate.o color.o StrToFloat.o FloatToStr2.o Value2Str.o

all : library clean_object_files
@echo Successful Build

#----------------------------------------
# compile all the *.c files in the directory
#----------------------------------------
%.o : %.c
$(CC) -Wall -c $<

#----------------------------------------
# create the library from the list of object files
#----------------------------------------
library : $(OBJECTS)
$(AR) libbxbasm.a $(OBJECTS)

#----------------------------------------
#remove all the object files
#----------------------------------------
clean_object_files :
@echo Cleaning Up
@del *.o

#----------------------------------------
#remove the object files and the library
#----------------------------------------
clean : clean_object_files
@echo Removing All Object and Library Files
@del *.a



SteveA

  • Guest
Re: BxbAsm
« Reply #176 on: April 23, 2012, 11:51:25 AM »
Hey James,
okay, let me study this for a bit.



jcfuller

  • Guest
Re: BxbAsm
« Reply #177 on: April 24, 2012, 05:14:21 AM »
Steve,
  While fixing my Radasm3 setup I noticed  jwasm is configured to use PellesC linker and librarian. This may be a better choice for your distribution of Bxbasm. Very liberal license and much better documentation than jwlink. I think all you need is permission from Pelle to include polink in your distribution .

James
 

SteveA

  • Guest
Re: BxbAsm
« Reply #178 on: April 24, 2012, 07:44:28 AM »
Hey James,

Very liberal license and much better documentation than jwlink.

I'll have a look.

On a side note:
[rant]
Boy I sure hate licenses. They always seem to have caveats.
Like, you can use it for this, but only if you are not using it for that.
"for educational purpose only", "for private usage only", "for non-commercial use",....etc.
There are licenses and versions of versions of licenses.

What ever happened to good 'ol Public Domain.
I like a clean Copywrite (c) and a simple disclaimer.
Give credit where credit is due and use it at your own risk.

When I first released Bxbasic I included a GPL.
I then pulled the license and released a statement indicating as much.

Why the need to make free software "free with strings attached" ?

People who write software aren't lawyers and shouldn't pretend they are.
What people don't understand is that the spoken word and the meaning of the law are two different things.
[/ rant]

SteveA

  • Guest
Re: BxbAsm
« Reply #179 on: April 24, 2012, 07:52:25 AM »
On another note,
I was playing around with creating Obj's from the small routines and making Lib's from the resulting code.
I think I can come up with a method of making it all work without too much complexity.
I just need to build a template of sorts to put it all together.
It would be nice if I could add it as a function of the IDE, (Wedit), but, I don't see a way to do that.
However, I do like using Hutch's Qeditor and it does make it easy to do that type of thing, just by modifying the menu.
Too bad there isn't a version of Qeditor for Linux.

Steve