Welcome, Guest. Please login or register.

Author Topic: I don't think I can learn C....  (Read 10455 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 all replies
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« 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 all replies
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #1 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #2 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 all replies
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #3 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 Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: I don't think I can learn C....
« Reply #4 on: April 03, 2003, 03:03:57 PM »
Quote
Quote

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

Anybody beaten this yet?


These with my half-working 68k gcc 2.95.2 setup:

mystery-68000-gcc                  968 ----rwed Today     16:41:16
mystery-68020-gcc                  928 ----rwed Today     16:40:14
2 files - 1896 bytes used

...I wonder if I missed something with SAS/C though, it should gererate smaller code imo.