From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 25 10:39:07 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8FD4B16A4CE for ; Mon, 25 Apr 2005 10:39:07 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by mx1.FreeBSD.org (Postfix) with ESMTP id 13F3F43D1D for ; Mon, 25 Apr 2005 10:39:07 +0000 (GMT) (envelope-from maslanbsd@gmail.com) Received: by wproxy.gmail.com with SMTP id 69so1202628wra for ; Mon, 25 Apr 2005 03:39:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fG6DEtIpLgG8CyD/JKDEPz6Unn/XKTjkfAQO78aG3sSx46ZlXR8aXxvDzBZpBZLg+q4Ivy0ar2ct+QlabHu7cR/zWLQITEVTlSdsBmCtGPGr4UcQUfTQfKE872bFGU8oFW0gLhtUZJnYlPyrfGvz+1Gf/yZ8IoIf1zA/BCukQ9M= Received: by 10.54.24.48 with SMTP id 48mr1849642wrx; Mon, 25 Apr 2005 03:39:03 -0700 (PDT) Received: by 10.54.99.7 with HTTP; Mon, 25 Apr 2005 03:39:03 -0700 (PDT) Message-ID: <319cceca05042503395f67e573@mail.gmail.com> Date: Mon, 25 Apr 2005 12:39:03 +0200 From: Maslan To: Tetsuji Maverick Rai In-Reply-To: <426B9965.2000003@vfemail.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <000f01c548a1$0eb33fd0$6702a8c0@IBM6C6CDABCD41> <426B9965.2000003@vfemail.net> cc: freebsd-hackers@freebsd.org cc: HHCHANG Subject: Re: about execute assembly exapmles under freebsd X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Maslan List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2005 10:39:07 -0000 hey if u need u to use linux calling way u will need to brandelf the executable (if it's elf) On 4/24/05, Tetsuji Maverick Rai wrote: > I refined my code to make the binary shorter. Your code is in Linux > system call convention (ie, arguments are in eax,ebx,ecx...), however in > FreeBSD by default arguments must be pushed in the stack. >=20 > -----t.s------------- > .section .data > output: > .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n" > .section .text > .globl _start > _start: > xor %eax, %eax > cpuid > mov $output, %edi # load address of output in edi > movl %ebx, 28(%edi) > movl %edx, 32(%edi) > movl %ecx, 36(%edi) > pushl $42 > mov $output, %eax > pushl %eax > pushl $1 > mov $4,%eax > push %eax > int $0x80 > add $16,%esp # of course you can omit this > xor %eax,%eax # this is shorter than "pushl $0; pushl $1; mov > $1,%eax" > push %eax > inc %eax > push %eax > int $0x80 > --------------t.s end---------- >=20 > and it works like this: >=20 > ---cut----- > freebsd53:~/tmp% as t.s -o t.o > freebsd53:~/tmp% ld t.o -o t > freebsd53:~/tmp% ./t > The processor Vendor ID is 'GenuineIntel' > ---cut----- >=20 >=20 > HHCHANG wrote: >=20 > >Hi, > >I couldn't execute assembly example under freebsd . > >The environment and tools I used were (in IBM X31 box): > >1. > >bash-2.05b# uname -a > >FreeBSD sexbear.localhost 5.3-STABLE FreeBSD 5.3-STABLE #3: Sun Feb 20 2= 1:55:06 UTC 2005 ?root@sexbear.localhost:/usr/obj/usr/src/sys/SEXBEAR??i= 386 > >2. > >bash-2.05b# as -v > >GNU assembler version 2.15 [FreeBSD] 2004-05-23 (i386-obrien-freebsd) us= ing BFD version 2.15 [FreeBSD] 2004-05-23 > > > >bash-2.05b# ld -v > >GNU ld version 2.15 [FreeBSD] 2004-05-23 > > > >3.(compile and execute the example) > >bash-2.05b# > > as -gstabs -o cpuid.o cpuid.s > > ld -o cpuid cpuid.o > > cpuid (no output after executing the program) > > gdb cpuid > > (gdb) run > > Starting program: /usr/local/src/code/chap04/cpuid > > Program exited with code 0340. > > (gdb) break *_start > > (gdb) run > > Program exited with code 0340. > >###################example in book################################### > >#cpuid.s Sample program to extract the processor Vendor ID > >.section .data > >output: > > .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n" > >.section .text > >.globl _start > >_start: > > movl $0, %eax > > cpuid > > movl $output, %edi > > movl %ebx, 28(%edi) > > movl %edx, 32(%edi) > > movl %ecx, 36(%edi) > > movl $4, %eax > > movl $1, %ebx > > movl $output, %ecx > > movl $42, %edx > > int $0x80 > > movl $1, > > %eax > > movl $0, %ebx > > int $0x80 > > > >###################example in book################################### > > > >I viewed the tutorial: http://www.int80h.org/bsdasm/. > >but I couldn't find any syntax error in the program. > >Could someone give me a hint where I could find the more information? > >Thanks~ > > > >Regards, > >_______________________________________________ > >freebsd-hackers@freebsd.org mailing list > >http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > >To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.or= g" > > > > > > >=20 > -- > Tetsuji 'Maverick' Rai > PGP Key fingerprint =3D 2021 6BF9 CEA3 73DE FF17 B326 F4DA F04E F784 3B8= 5 > gpg fingerprint > Aviation Jokes: http://www.geocities.com/tetsuji_rai/ > Profile http://maverick.ns1.name/ > http://maverick.IsASecret.com/ >=20 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= " >=20 --=20 I'm Searching For Perfection, So Even If U Need Portability U've To Use Assembly ;-) http://www.maslanlab.org