Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 05 Mar 2000 00:19:46 -0500
From:      "Thomas M. Sommers" <tms2@mail.ptd.net>
To:        freebsd-Hackers@freebsd.org
Subject:   Re: Can't write to stdout in assembly
Message-ID:  <38C1EE72.B72F520D@mail.ptd.net>
References:  <20000304194140.48F3D2E803@hermes.tue.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
Marco van de Voort wrote:
> 
> > >From what I understand, the following should print "Hello, world." on
> > stdout. I stole the code from the Linux HOWTO, but I think it should
> > work on FreeBSD as well. Instead, the call to write returns 9 (EBADF).
> 
> I disassembled FreeBSD programs (create a small C prog, compile, and use
> objdump), and it looks more like this: (I haven't tested this yet, but it is definitely
> stack based, not register based, the part which I haven't tested is if the placing
> the int $0x80 behind a call is required)
> 

It turns out that placing the int $0x80 behind a call is required. I
infer that 
the kernel does not look for the arguments at the top of the stack, but
farther
down. When you think about it, that makes some sense, since any sane
person would
call the kernel through libc, and not directly. Thanks for the help.

In the remote chance that anyone is interested, here is the code that
works:

.data
msg:	.string "Hello, world.\n"
		len = . - msg - 1
.text
		.global _start
_start:
		pushl	$len
		pushl	$msg
		pushl	$1
		movl	$4, %eax
		call	make_syscall
		addl	$12, %esp

		movl	$1, %eax
		pushl	$0
		call	make_syscall

make_syscall:
		int	$0x80
		ret


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?38C1EE72.B72F520D>