NO

Author Topic: Lzw compress/expand demo -- no libs, no dlls, ppj included  (Read 12631 times)

Rainbow Sally

  • Guest
Lzw compress/expand demo -- no libs, no dlls, ppj included
« on: December 30, 2004, 03:43:55 PM »
This is a demo of the lzw algorithm for compress and expand.  The resulting exe that does both (for demo purposes) compiles to about 4K.

Compression is decent and fast.  The bulk of the zip file is the text file.

When you run your app after you compile it, enter

   LZW.HTM

Which is the test file name.  

the demo will produce new files named test.lzw (compressed) and test.out (expanded again).

Change the name of test.out to test.htm and it should appear exactly as the intput file did.

    Other features:

    The PPJ file is included (with relative paths so it should work in any folder on any drive).  

    It is set up to produce a (almost) minimum size application.  

    The source code is modified to replace getc with fgetc to avoid crash in msvcrt.  (There are other file functions in that dll that are flaky too.)


Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #1 on: December 30, 2004, 08:51:15 PM »
Hi Rainbow Sally,

Here is your executable reduced to 3072 bytes without merging sections, ppj included.
Code it... That's all...

Rainbow Sally

  • Guest
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #2 on: December 31, 2004, 05:52:55 PM »
Quote from: "Vortex"
Hi Rainbow Sally,

Here is your executable reduced to 3072 bytes without merging sections, ppj included.


Thank you Vortex.  

Cool stuff.

Rainbow Sally

  • Guest
2 Vortext -- HowJuDooThat?
« Reply #3 on: December 31, 2004, 06:14:32 PM »
Hey!  ???

What did you compile the crt0cons.asm with?

I tried

Code: [Select]

    pocc crt0cons.asm  


from the command line but pocc doesn't like it.

External assembler?

Also, I'm not sure what version of the ide you have but I got an error message about a tags file not being recognized, then poide crashed.  I removed the lzs.tags and stuff and it works fine (since the obj file already existed) but I may be missing an important step as a result.

To other users.  This is really great stuff.  We see how to change the entry address to do another function (or init) before jumping to main and how to use an obj file (possibly created by other applications?) in our own C projects.

To Vortex.  This is the kind of thing I may need to do to get more C++ obj files working in Pelles C.  Thanks for these demos.  I'm learning a lot and it's easy and it's fun.

.

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #4 on: January 01, 2005, 12:00:47 PM »
Hi Rainbow Sally,

Happy new year :)

Yes, just as you said, I used an external assembler, MS Macro Assembler - MASM.  To get this tool, have a look at Hutch's homepage - the Masm32 project:

http://movsd.com/

crt0cons.asm is tiny C startup code reducing the size of the final executable. crt0gui.asm is the GUI version.

Assembling the source file ( ml.exe is the 32-bit assembler.) :
Code: [Select]

ml /c /coff crt0cons.asm


/c     : assemble only ( no linking )
/coff : choose MS COFF object file format

Version of my IDE = 2.90.8

I don't have any idea why these tag files make crash the IDE. Maybe, Pelle can offer a solution.

About using C startup codes, you can have a look at my little project:

http://smorgasbordet.com/phpBB2/viewtopic.php?t=88
Code it... That's all...

Rainbow Sally

  • Guest
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #5 on: January 02, 2005, 02:10:11 AM »
Quote from: "Vortex"
Hi Rainbow Sally,


About using C startup codes, you can have a look at my little project:

http://smorgasbordet.com/phpBB2/viewtopic.php?t=88



Been meaning to do that.  I will.

To All. I tried and tried to get a smaller "PE" file (exe's and dll's are Portable Executables in MS terminology). I used assembler in PellesC but  I couldn't break Vortex's record for small.  

This isn't important stuff.  It's just fun.  It's like putting racing slicks on your lawnmower, in a way, so this isn't going to be important for most C programmers.  

We're only talking about a few bytes, actually it's the size of section alignment that Vortex is beating my sizes on because msvcrt creates a new .rdata section, forcing another section alignment for proc addresses Vortex has apparently found another way to get.  (And I'll find out what it is, and duplicate it from asm in PellsC, if I can.  LoadLibrary?  GetProcAddress?  That might do it...  

To Vortex.  I really am enjoying this.  I've got a project I need to get back on but it should be done in a few houts and I'll take a look at your other posts.

.

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #6 on: January 02, 2005, 10:40:58 AM »
Hi Rainbow Sally,

The Microsoft PE file specification says that the minimum size of a valid executable should be 1024 bytes. Setting the alignment value to 16, I got an executable of 576 bytes. You can even create smaller executables, but your executable smaller than 1024 bytes may not run every version of Windows.
Code it... That's all...

Rainbow Sally

  • Guest
Lzw compress/expand demo -- no libs, no dlls, ppj included
« Reply #7 on: January 02, 2005, 03:50:05 PM »
Quote from: "Vortex"
Hi Rainbow Sally,

The Microsoft PE file specification says that the minimum size of a valid executable should be 1024 bytes.


This is ssergorP, not Progress, but...

Thank you so much Vortex!!  Another mystery solved.


--------------
Probably because M$ doesn't know how to make them any smaller?

Anonymous

  • Guest
Amazing
« Reply #8 on: September 29, 2005, 12:08:01 AM »
I think that that is a brilliant idea.

Gerome

  • Guest
Re: Lzw compress/expand demo -- no libs, no dlls, ppj includ
« Reply #9 on: September 29, 2005, 10:20:50 AM »
Hello,

This works fine only with text files.
If you try to compress an XLS file it'll create a larger file :?
How is this possible?

Quote from: "Rainbow Sally"
This is a demo of the lzw algorithm for compress and expand.  The resulting exe that does both (for demo purposes) compiles to about 4K.

Compression is decent and fast.  The bulk of the zip file is the text file.

When you run your app after you compile it, enter

   LZW.HTM

Which is the test file name.  

the demo will produce new files named test.lzw (compressed) and test.out (expanded again).

Change the name of test.out to test.htm and it should appear exactly as the intput file did.

    Other features:

    The PPJ file is included (with relative paths so it should work in any folder on any drive).  

    It is set up to produce a (almost) minimum size application.  

    The source code is modified to replace getc with fgetc to avoid crash in msvcrt.  (There are other file functions in that dll that are flaky too.)


Timppa

  • Guest