Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 May 2000 12:36:48 +0100
From:      "Marco van de Voort" <marcov@stack.nl>
To:        hackers@freebsd.org
Subject:   APJ Article
Message-ID:  <20000506103622.40A382E803@hermes.tue.nl>
In-Reply-To: <20000505224429.B4423971F@toad.stack.nl>

next in thread | previous in thread | raw e-mail | index | archive | help


> 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)
<http://www.stack.nl/~marcov/xtdlib.htm>;


Marco van de Voort (MarcoV@Stack.nl)
<http://www.stack.nl/~marcov/xtdlib.htm>;



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000506103622.40A382E803>