Date: Sat, 15 Jun 1996 07:45:09 +0200 (MET DST) From: grog@lemis.de (Greg Lehey) To: randyd@nconnect.net (Randy DuCharme) Cc: questions@freebsd.org Subject: Re: Assembler programming Message-ID: <199606150545.HAA13124@allegro.lemis.de> In-Reply-To: <31C18946.2807@nconnect.net> from "Randy DuCharme" at Jun 14, 96 10:46:14 am
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606150545.HAA13124>
