Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pepper!cmcmanis From: cmcmanis%pepper@Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga Subject: Re: Linking without startup code or libraries Message-ID: <92710@sun.uucp> Date: 7 Mar 89 02:42:08 GMT References: <92203@sun.uucp> Sender: news@sun.uucp Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Distribution: na Organization: Sun Microsystems, Mountain View Lines: 102 In article <92203@sun.uucp> I wrote: > Yes, with Lattice 5.0x it is possible to have nothing but > blink myprog.o to myprog This is correct. > (which sometimes you can just execute myprog.o if there are no externals > at all) This is incorrect. > Essentially, you will have to define your lib pointers internally and use > the prototypes for direct linkage to the libraries. Then in a followup article shadow@pawl.rpi.edu writes: > Can you give me a short simple example that will work for this? Say, > the classic "Hello, world!" program? I tried something like this: To which I reply "Certainly" and here it is : To make this program run compile it like so : lc -v -b0 sm.c blink sm.o to sm You must use -b0 or somehow set up A4 to point to your data segment ahead of time. (Relative addressing on code still works fine) ------- /* Hello world very simply */ #include /* always useful */ #include /* probably extraneous */ #include /* Defines dosname */ #include /* Essential for inline calls */ #include /* ditto */ ULONG **SysBase = (ULONG **) 4; /* The one "known" address */ ULONG *ExecBase; /* Needed for Exec functions */ struct DOSBase *DOSBase; /* Needed for DOS functions */ char msg[] = "Hello World\n"; /* Ye old message */ _main() { ExecBase = *SysBase; DOSBase = (struct DOSBase *)OpenLibrary(DOSNAME,0); Write(Output(), msg, sizeof(msg)); (void) CloseLibrary(DOSBase); return (0); } And the assembly that Lattice generates for this is : ------- Lattice AMIGA 68000-68020 OBJ Module Disassembler V5.00 Copyright ) 1988 Lattice Inc. All Rights Reserved. Amiga Object File Loader V1.00 68000 Instruction Set EXTERNAL DEFINITIONS __main 0000-00 _SysBase 0000-01 _msg 0004-01 _ExecBase 0000-02 _DOSBase 0004-02 SECTION 00 "text" 00000050 BYTES | 0000 48 E7 30 02 MOVEM.L D2-D3/A6,-(A7) | 0004 20 79 00 00 00 00-01 MOVEA.L 01.00000000,A0 | 000A 23 D0 00 00 00 00-02 MOVE.L (A0),02.00000000 | 0010 43 F9 00 00 00 12-01 LEA 01.00000012,A1 | 0016 70 00 MOVEQ #00,D0 | 0018 2C 78 00 04 MOVEA.L 0004,A6 | 001C 4E AE FD D8 JSR FDD8(A6) | 0020 23 C0 00 00 00 04-02 MOVE.L D0,02.00000004 | 0026 C1 8E EXG D0,A6 | 0028 4E AE FF C4 JSR FFC4(A6) | 002C 22 00 MOVE.L D0,D1 | 002E 41 F9 00 00 00 04-01 LEA 01.00000004,A0 | 0034 24 08 MOVE.L A0,D2 | 0036 76 0D MOVEQ #0D,D3 | 0038 4E AE FF D0 JSR FFD0(A6) | 003C 22 4E MOVEA.L A6,A1 | 003E 2C 78 00 04 MOVEA.L 0004,A6 | 0042 4E AE FE 62 JSR FE62(A6) | 0046 70 00 MOVEQ #00,D0 | 0048 4C DF 40 0C MOVEM.L (A7)+,D2-D3/A6 | 004C 4E 75 RTS SECTION 01 "data" 00000020 BYTES 0000 00 00 00 04 48 65 6C 6C 6F 20 57 6F 72 6C 64 0A ....Hello World. 0010 00 00 64 6F 73 2E 6C 69 62 72 61 72 79 00 00 00 ..dos.library... SECTION 02 "udata" 00000008 BYTES ---------- When blinked results in an executable that is 224 bytes long. You can probably trim that some. (It doesn't have to return 0). --Chuck McManis uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com These opinions are my own and no one elses, but you knew that didn't you.