From owner-freebsd-questions Fri Jun 14 23:16:51 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA29287 for questions-outgoing; Fri, 14 Jun 1996 23:16:51 -0700 (PDT) Received: from ref.tfs.com (ref.tfs.com [140.145.254.251]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id XAA29282 for ; Fri, 14 Jun 1996 23:16:49 -0700 (PDT) Received: from diablo.ppp.de (diablo.ppp.de [193.141.101.34]) by ref.tfs.com (8.7.5/8.7.3) with SMTP id XAA11857 for ; Fri, 14 Jun 1996 23:16:42 -0700 (PDT) Received: from allegro.lemis.de by diablo.ppp.de with smtp (Smail3.1.28.1 #1) id m0uUobR-000QanC; Sat, 15 Jun 96 08:12 MET DST From: grog@lemis.de (Greg Lehey) Organisation: LEMIS, Schellnhausen 2, 36325 Feldatal, Germany Phone: +49-6637-919123 Fax: +49-6637-919122 Received: (grog@localhost) by allegro.lemis.de (8.6.9/8.6.9) id HAA13124; Sat, 15 Jun 1996 07:45:09 +0200 Message-Id: <199606150545.HAA13124@allegro.lemis.de> Subject: Re: Assembler programming To: randyd@nconnect.net (Randy DuCharme) Date: Sat, 15 Jun 1996 07:45:09 +0200 (MET DST) Cc: questions@freebsd.org In-Reply-To: <31C18946.2807@nconnect.net> from "Randy DuCharme" at Jun 14, 96 10:46:14 am X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Randy DuCharme writes: > > Greetings, > This may be another dumb question, but can one do 'pure' assembly > language programming under FreeBSD? Yes. > If so, how? With some difficulty. The assembler is called as, and is a standard part of the system. It's used by the compiler, for example, which outputs assembler code. Unfortunately, the code is not compatible with Intel mnemonics and syntax. Here's an example: + To see how this all works, let's take the following small program and look at + different aspects of what the compiler and assembler do with it in the next few + sections: + + char global_text [] = "This is global text in the data area"; + void inc (int *x, int *y) + { + if (*x) + (*x)++; + else + (*y)++; + puts (global_text); /* this is an external function */ + puts ("That's all, folks"); + } + + We compile this program on a BSD/OS machine using gcc version 2.5.8, with + maximum optimization and debugging symbols: + + $ gcc -O2 -g -S winc.c + + The -S flag tells the compiler control program to stop after + running the compiler. It stores the assembly output in winc.s, which + looks like this: + + .file "winc.c" + gcc2_compiled.: + ___gnu_compiled_c: + .stabs "/usr/lemis/book/porting/grot/",100,0,0,Ltext0 name of the source directory + .stabs "winc.c",100,0,0,Ltext0 name of the source file + .text select text section + Ltext0: internal label: start of text + .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0 + .stabs "char:t2=r2;0;127;",128,0,0,0 + ... a whole lot of standard debugging output omitted + .stabs "void:t19=19",128,0,0,0 + .globl _global_text specify an externally defined symbol + .data select data section + .stabs "global_text:G20=ar1;0;36;2",32,0,1,0 debug info for global symbol + _global_text: variable label + .ascii "This is global text in the data area\0" and text + .text select text section + LC0: + .ascii "That's all, folks\0" + .align 2 start on a 16 bit boundary + .globl _inc define the function inc to be external + _inc: start of function inc + .stabd 68,0,3 debug information: start of line 3 + pushl %ebp + movl %esp,%ebp + movl 8(%ebp),%eax + movl 12(%ebp),%edx + .stabd 68,0,4 debug information: start of line 4 + LBB2: + cmpl $0,(%eax) + je L2 + .stabd 68,0,5 debug information: start of line 5 + incl (%eax) + jmp L3 + .align 2,0x90 + L2: + .stabd 68,0,7 debug information: start of line 7 + incl (%edx) + L3: + .stabd 68,0,8 debug information: start of line 8 + pushl $_global_text + call _puts + .stabd 68,0,9 debug information: start of line 9 + pushl $LC0 + call _puts + .stabd 68,0,10 debug information: start of line 10 + LBE2: + leave + ret + .stabs "inc:F19",36,0,3,_inc debug information for inc + .stabs "x:p21=*1",160,0,2,8 debug information for x + .stabs "y:p21",160,0,2,1 debug information for y + .stabs "x:r21",64,0,2,0 + .stabs "y:r21",64,0,2,2 + .stabn 192,0,0,LBB2 + .stabn 224,0,0,LBE2 > In DOS / WINNT I used MASM 6.11. Completely different, I'm afraid. > Any good books on this subject? Nothing really, I suppose. My "Porting UNIX Software" (O'Reilly) has a number of examples, but it's not an introduction. The gas (GNU as) documentation explains a little bit, but it's not an introduction either. > Any recommendations on GOOD reading on the GCC compiler & libraries? Mike Loukides and Andy Oram (O'Reilly) are writing a book on using GNU software. I don't know when it'll appear, but it should be Real Soon Now.