From owner-freebsd-hackers Sat May 6 3:36:29 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from kweetal.tue.nl (kweetal.tue.nl [131.155.2.7]) by hub.freebsd.org (Postfix) with ESMTP id 00AA537B784 for ; Sat, 6 May 2000 03:36:25 -0700 (PDT) (envelope-from marcov@toad.stack.nl) Received: from hermes.tue.nl [131.155.2.46] by kweetal.tue.nl (8.9.3) for id MAA23382 (ESMTP); Sat, 6 May 2000 12:36:23 +0200 (MDT) Received: from deathstar (n126.dial.tue.nl [131.155.209.125]) by hermes.tue.nl (Postfix) with ESMTP id 40A382E803 for ; Sat, 6 May 2000 12:36:22 +0200 (CEST) From: "Marco van de Voort" To: hackers@freebsd.org Date: Sat, 6 May 2000 12:36:48 +0100 Subject: APJ Article In-reply-to: <20000505224429.B4423971F@toad.stack.nl> X-mailer: Pegasus Mail for Win32 (v3.12b) Message-Id: <20000506103622.40A382E803@hermes.tue.nl> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > As a die-hard assembly language programmer, I was very pleased when recently > someone posted a link to his Hello, World assembly language code here. I did that as a die-hard pascal programmer: -) This is one of those things every non C programmer runs into. > I played with his code a bit, then wrote a very simple filter in assembly > language. I then converted it to an article on System Calls in FreeBSD, > and submitted it to Assembly Programming Journal, which is a bi-monthly > on-line magazine. > > If anyone is interested, the text of the article (includes the code for > the filter) is at http://www.whizkidtech.net/syscall.txt > > I pose a question in it (where can an assembly language program find its > command line): If anyone knows the answer, I'd love to hear it! Locate directory csu (I believe it is in /usr/src/lib/csu), and compile crt0.c with -S and -O3 or so. (which simplifies the assembler) (I believe this won't work with a recent compiler, I had to do it on a system with a 2.7.x compiler) You will find something like the following code in it like this: (The U_SYSLINUX labels are Free Pascal variables that are loaded, I had to 'fix' crt0 for that) movl %edx,%edx #NO_APP leal 8(%ebp),%edi movl %edi,U_SYSLINUX_ARGV mov -4(%edi),%eax movl %eax,U_SYSLINUX_ARGC movl 4(%ebp),%ebx leal 12(%ebp,%ebx,4),%esi movl %esi,U_SYSLINUX_ENVP movl %esi,environ testl %ebx,%ebx jle .L2 movl 8(%ebp),%eax testl %eax,%eax je .L2 movl %eax,__progname cmpb $0,(%eax) je .L2 Well, argv, argc, the enviroment, what more can you want :-) Anyway, the generated assembler source will also reveal how to parse that structure. You can also rip out all libc initialisation code (or I can sent you my version, in which you only have to comment those U_SYSLINUX lines) if you don't link to libc. Marco van de Voort (MarcoV@Stack.nl) Marco van de Voort (MarcoV@Stack.nl) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message