🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5737

Small hello.c

#5737
From: Doug Walker
Date: Wed, 10 Oct 1990 18:33
53 lines
1932 bytes
I posted a 'small' hello world program not too long ago in response
to someone asking why hello world with printf() was so big... turns
out there were SEVERAL bugs in even that small program.  Here's a
small hello world program that comes out to 124 bytes for me that
does the job:


; /*  
;EXECUTE THIS FILE AS A SHELL SCRIPT AND IT WILL COMPILE ITSELF

lc -cwus -O -v -j73 hw
blink from hw.o to hw sc sd
quit
*/

#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>


void foo(void)
{
   struct DosLibrary *DOSBase;

   if(DOSBase = OpenLibrary("dos.library", 0))
   {
      Write(Output(), "Hello, World!\n", 15);
      CloseLibrary(DOSBase);
   }
}

A couple of things to note:

   1. DOSBase is a local, not a global, because no startup code is used
      and thus A4 is not set up to point to the base of global storage.

   2. The -cs option is REQUIRED for the same reason as (1) - with -cs,
      strings are stored in the code section and accessed PC-relative;
      otherwise, they are stored in the (nonexistent) data section.
      The "Hello, World!\n" string must be accessed PC-relative.

   3. DOSBase is, of course, case-sensitive.

   4. The -v option is necessary to avoid stack-checking code, which refers
      to external variables.


  *****                                          NOW AT 9600 DUAL STANDARD!
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
 *|. o.| ||
  | o  |//     For all you do, this bug's for you!
  ====== 
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 
Technical Details
Message-ID: <1990Oct10.183343.17073@unx.sas.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!sol.ctr.columbia.edu!emory!gatech!mcnc!rti!mozart!walker

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!sol.ctr.columbia.edu!emory!gatech!mcnc!rti!mozart!walker
From: walker@unx.sas.com (Doug Walker)
Newsgroups: comp.sys.amiga.tech
Subject: Small hello.c
Message-ID: <1990Oct10.183343.17073@unx.sas.com>
Date: 10 Oct 90 18:33:43 GMT
Organization: SAS Institute Inc.
Lines: 53