From owner-freebsd-questions@FreeBSD.ORG Thu Nov 12 15:38:33 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88183106566B for ; Thu, 12 Nov 2009 15:38:33 +0000 (UTC) (envelope-from djackson452@gmail.com) Received: from mail-qy0-f108.google.com (mail-qy0-f108.google.com [209.85.221.108]) by mx1.freebsd.org (Postfix) with ESMTP id 39BDF8FC24 for ; Thu, 12 Nov 2009 15:38:32 +0000 (UTC) Received: by qyk6 with SMTP id 6so109917qyk.3 for ; Thu, 12 Nov 2009 07:38:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=nNXqqGqdUXBp/qPq+VRqCR1xsF1Z2isIms3UZ4lv1N4=; b=altdDz6I11sK+GBIWwAEXXe9iWDTNVf55iQq3qLV1q+oiX6e0dO/fR4c9OZi8DOyks fpDAadajkRit2PGUltt4y89xE4c2QV0aaaJE9qJbch8LOFP5BJZuPW89Uj5adCH8YP7h fZlI9VhWn0/as04janLcGhk75dMm4qosk7Fbs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=dOGGSoOrS3ahdnf61AlwzfVZ6kte0NQD2aRJxAaHKkKRydoNHRKL1LlXF45PdMeKVG ZbwWv0iaWRDHw7wP9Yt8SdQAHYEmHNVz1WbxJdox+LmHCglJ7yKGAcO4GKEZFq/ZwHOf iO/vtcyGg9AZQIXEkIxSiUqWeTpP2Otd7Dg+s= Received: by 10.224.102.207 with SMTP id h15mr1665004qao.139.1258040312176; Thu, 12 Nov 2009 07:38:32 -0800 (PST) Received: from ?192.168.1.103? (pool-96-254-203-152.tampfl.fios.verizon.net [96.254.203.152]) by mx.google.com with ESMTPS id 8sm1355876yxb.61.2009.11.12.07.38.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 12 Nov 2009 07:38:31 -0800 (PST) Message-ID: <4AFC2BDF.7060405@gmail.com> Date: Thu, 12 Nov 2009 10:38:07 -0500 From: David Jackson User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Charlie Kester , freebsd-questions@freebsd.org References: <4AFB13D9.9050507@gmail.com> <20091112013240.GA21567@comcast.net> <20091112014515.GB21567@comcast.net> In-Reply-To: <20091112014515.GB21567@comcast.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: Problems with FreeBSD assembly X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2009 15:38:33 -0000 Charlie Kester wrote: > On Wed 11 Nov 2009 at 17:32:41 PST Charlie Kester wrote: > > One more thing: > >> Notice that the system call number (or any other dword) should also be >> pushed onto the stack before the int 80h. > > The reason for this is given at the top of the page: > > although the kernel is accessed using int 80h, it is assumed the > program will call a function that issues int 80h, rather than issuing > int 80h directly. > > So the extra dword pushed onto the stack takes the place of the return > address from the function the kernel expects to have been called. > And since you're not actually using as a return address, it doesn't > matter what value it actually has. The kernel doesn't use it for > anything; it just expects it to be there in a properly arranged stack > frame. > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" The push eax is what made it work. So that was the problem. Stdin and stdout do not need to opened before they are used, as in C. Thank you everyone for your help on this, that solved it. Here is the code that works: section .data hello db 'Hello, World!', 0xa hbytes equ $ - hello section .text global _start _start: push dword hbytes push dword hello push dword 1 mov eax,0x4 push eax int 0x80 add esp,16 push dword 0 mov eax,0x1 push eax int 0x80