Welcome, Guest. Please login or register.

Author Topic: I don't think I can learn C....  (Read 10524 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #29 on: April 02, 2003, 09:47:28 PM »
Quote
The size of the stdio / startup stuff has a lot of impact on some systems.

Yes indeed. So why not skip stdio & startup?

Here is what I did:

#include
#include

#include
#include

#define putchar(x) FPutC(Output(),x)

struct DosLibrary *DOSBase;

void entry(void)
{
  struct ExecBase *SysBase = *(struct ExecBase **)4;
  DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37);
  if (DOSBase)
  {
    main(1,NULL,NULL);
    CloseLibrary((struct Library *) DOSBase);
  }
}

//#include
.... rest of the original code...

Then compile with size optimization, link without startup code, and strip resulting exe:

68000, AmigaOS (SAS/C 6.58):
mystery                           1048 ----rwed Today     23:32:37

PowerPC, MorphOS (gcc 2.95.3):
mystery                           2200 ----rwed Today     23:32:42

Next step: Optimize the generated asm code. :-)
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #30 on: April 02, 2003, 09:53:21 PM »
About obfuscated C, here's my .sig block I wrote some years ago:

--
l=2001;main(i){float o,O,_,I,D;for(;O=I=l/571.-1.75,l;)for(putchar(--l%80?
i:10),o=D=l%80*.05-2,i=31;_=O*O,O=2*o*O+I,o=o*o-_+D,o+_+_<4+D&i++<87;);puts
("  Harry 'Piru' Sintonen http://www.iki.fi/sintonen");}

..It's a twoliner if you get rid of the last info puts(). :-)
 

Offline N7VQM

  • Sr. Member
  • ****
  • Join Date: Dec 2002
  • Posts: 272
    • Show only replies by N7VQM
Re: I don't think I can learn C....
« Reply #31 on: April 02, 2003, 10:20:39 PM »
I used MS VC++ to compile the code.

The obj file length is 2015 bytes.
The first exe I VC generated was about 36K long.  With size optimization, it was 32303 bytes.  After some tinkering, I got it down to 28Kb.  

Then, just to be cheeky, I ran it thru PECompact V1.32.  That got it down to 13824 bytes.  Yeah....I know that's cheating! :-D
\\"...an error of 1 is much less significant in counting the population of the Earth than in counting the occupants of a phone booth.\\" - Michael T. Heath, Scientific Computing...
 

Offline AtheistTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
Re: I don't think I can learn C....
« Reply #32 on: April 02, 2003, 10:57:52 PM »
Quote

Piru wrote:

68000, AmigaOS (SAS/C 6.58):
mystery                           1048 ----rwed Today     23:32:37

PowerPC, MorphOS (gcc 2.95.3):
mystery                           2200 ----rwed Today     23:32:42


Now, could one attribute the 1152 byte difference to RISC overhead (needing more instr, per CISC command)?

Quote

Piru wrote:
Next step: Optimize the generated asm code. :-)


Major BrainStrain could result in ones being carted away in a strait jacket, or perhaps, return sanity and clearity of the Universe for another?  :-D

AmigaOne! Has this made a point?
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline AtheistTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
Re: I don't think I can learn C....
« Reply #33 on: April 02, 2003, 11:05:45 PM »
Quote

Karlos wrote:

Check out the winbloat! 30kb of sh*t linked just to make the exe :-D



Hello Karlos,

Could you imagine 10 or 20 commands in the C: (I mean ms-dos/windos) directory, with that kind of non-sense? NOT!!!

AmigaOne! If only it were in assembler!  :-D  :-D  :-D
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #34 on: April 02, 2003, 11:35:04 PM »
Quote

Atheist wrote:
Quote

Karlos wrote:

Check out the winbloat! 30kb of sh*t linked just to make the exe :-D



Hello Karlos,

Could you imagine 10 or 20 commands in the C: (I mean ms-dos/windos) directory, with that kind of non-sense? NOT!!!

AmigaOne! If only it were in assembler!  :-D  :-D  :-D


-edit-

You should see the sodding System32 folder!

-edit-

To be fair, the stuff in your C: directory is

1) usually written in asm (up to 3.1 anyhow)
2) Relies on AmigaOS dos.library for IO / startup

For example, the smallest hello world I got in

1) standard ANSI C : 20 kB (with stormC stdio)
2) ANSIC / dos.libnrary 500 odd bytes
3) asm / dos.library about 100 bytes

It's a real pity that exec.library RawDoFmt() doens't have proper C printf() templating - we could have a very compact stdio then.

But then again, it was written with BCPL in mind :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #35 on: April 02, 2003, 11:56:21 PM »
Quote

My guess is

1) the original text is compressed with something like LZ or dynamic huffman style compression, encoded into the big string in the middle



Hmm, if you zip up the output it compacts down to 296 bytes (WinZip, max compression), so maybe I'm onto something...;-)
int p; // A
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #36 on: April 03, 2003, 01:24:08 AM »
Quote
Now, could one attribute the 1152 byte difference to RISC overhead (needing more instr, per CISC command)?


ELF is not as compact fileformat as amiga hunk format is. In fact you could sqeeze some extra bytes out of it by compacting the ELF header and stuff (I've seen it done on linux x86). The ELF fileformat size overhead only starts to play a role with extremely small executables.

As a rule of thumb the same PPC code is roughly 2x 68k code size. This varies and depends on the code itself, of course.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #37 on: April 03, 2003, 01:42:43 AM »
Quote
For example, the smallest hello world I got in

1) standard ANSI C : 20 kB (with stormC stdio)
2) ANSIC / dos.libnrary 500 odd bytes
3) asm / dos.library about 100 bytes

But then again, it was written with BCPL in mind

Heh, this reminds me of another project, the shortest possible hello world in assembler.

You asked for it, and here it is: the smallest possible Hello World program as amiga executable (feel free to prove me wrong, though):

Main:
 bsr.b  .main
 dc.b   'Hello, World!',10
.main:
 move.l $AC(a2),a4
 move.l (sp)+,d1
 moveq  #14,d2
 moveq  #12,d0
 jmp    (a5)

That is:
- 14 bytes of code
- 14 bytes of data

Total 64 bytes as compiled to a executable. You can shorten the string to "Hello World\n", and thus have just 12 bytes of data, but the executable size remains as 64 due to padding.

And surprise surprise, the code (ab)uses some BCPL vector (globvec). :-)
 

Offline jeffimix

  • Hero Member
  • *****
  • Join Date: Jan 2003
  • Posts: 853
    • Show only replies by jeffimix
Re: I don't think I can learn C....
« Reply #38 on: April 03, 2003, 02:02:22 AM »
An OS in assembly, well this ones X86 but.... MenuetOS.org its a GUI enhanced  operating system, fits on a single floppy.  ITs written entirely in ASM.. the floppy comes with Tasm I believe (or Fasm maybe?) an MP3 player, a cd audio player, a maze thing, and some other stuff. Its creepy what can be done with a bootable floppy.  :idea:  :shocked:
\\"The only benchmarks that matter is my impression of the system while using the apps I use. Everything else is opinion.\\" - FooGoo
 

Offline Aragorn

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 25
    • Show only replies by Aragorn
Re: I don't think I can learn C....
« Reply #39 on: April 03, 2003, 02:34:33 AM »
object file on sparc/sunos/gcc  1896 bytes
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #40 on: April 03, 2003, 10:10:39 AM »
Quote

Piru wrote:
68000, AmigaOS (SAS/C 6.58):
mystery                           1048 ----rwed Today    


Anybody beaten this yet?

I might see what vbcc does for ppc it tonight...
int p; // A
 

Offline Crumpster

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 215
  • Country: gb
    • Show only replies by Crumpster
Re: I don't think I can learn C....
« Reply #41 on: April 03, 2003, 10:32:28 AM »
Wow, I don't come here for one evening cos of the football and this thread doubles in size!!

Does anyone know what tricks to use on gcc to get the end file size down.

I'm a newbee when it comes to gcc, i can compile and change the output filename from a.out, and thats it!! :-?

Cheers,

Crumpy
A1-XE - G4 800MHz, 1GB RAM, 80GB HDD, Radeon 9250, OS 4.1
A1200T - PPC603 240MHz / 68040 50MHz, 128MB RAM, Mediator, OS 3.9 / 4.1
A1200 (No. 2) - M-TEC 68030 50MHz, 4GB CF, KS 3.0, OS 3.0
A500 - ACA500 with ACA1232.
CDTV - in Progress: SCSI, 9 pin joy/mouse connectors, KS switcher.

Non-CBM - Atari STe, Atari Falcon, Apple ][e, ZX Spectrum, CPC6128.
Gone but not forgotten (and slowly getting them back): CPC464, C64, Vic-20.

I may have a problem
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #42 on: April 03, 2003, 10:36:52 AM »
Hi Crumpy,

Well, a quick summary. We went through the 'how big does the standard library bloat it out'

So we checked only the object size (not the exe). Unsurprisingly for my Win32 char mode exe attempt the stdio stuff was 20 times bigger than the actual code.

Different folks, different mileage...

Piru gave us an example of super minimalist startup code for AmigaOS and got it down to 1K :-)

I rambled about how I thought the thing worked...

You return and the thread is twice as long :-D
int p; // A
 

Offline whabang

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 7270
    • Show only replies by whabang
Re: I don't think I can learn C....
« Reply #43 on: April 03, 2003, 11:44:58 AM »
AARGH! By all gods and somewhat  important deities! :-o :-o  :-o

I was planning to learn C or C++, but this is too much!
/me runs back home to give a big hug to FreePascal :-D
Beating the dead horse since 2002.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #44 from previous page: April 03, 2003, 11:47:09 AM »
Quote

whabang wrote:
AARGH! By all gods and somewhat  important deities! :-o :-o  :-o

I was planning to learn C or C++, but this is too much!
/me runs back home to give a big hug to FreePascal :-D


Fear not, for 'tis merely an exmple of confusication - with a capital C :-)

No real program would look like this. Unless part of the Win32 kernel :-D
int p; // A