Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.hawaii.edu!ames!agate!spool.mu.edu!howland.reston.ans.net!gatech!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news From: j@uriah.heep.sax.de (J Wunsch) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: GNU assembler Date: 18 Jul 1996 11:35:48 GMT Organization: Private BSD site, Dresden Lines: 49 Message-ID: <4sl7ik$53o@uriah.heep.sax.de> References: <31ED89D2.41C6@raleigh.ibm.com> Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) NNTP-Posting-Host: localhost.heep.sax.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: knews 0.9.6 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Tony Rynan <rynan@raleigh.ibm.com> wrote: > I have created a file called fred.s that contains a single nop. > I run "as -o stuff fred.s" and then "ld stuff". An a.out is produced > that automagically core dumps (segmentation violation). You've fallen off the end of your program, until it eventually hit an unassigned memory page. When programming assembler, you have to call _exit (or __exit) manually. For the i386 architecture, all symbols in the C library have a leading underscore, so exit(3) is _exit, while _exit(2) is __exit. You need the C library for system calls, unless you plan to write your own syscall wrappers. The latter is even more unportable however. > Can anyone give me a few clues (or examples) on how to write and > compile a piece of assembler ???? j@uriah 117% cat hw.s .text hwstring: .ascii "Hello, world!\n" hwlen = . - hwstring .globl entry entry: pushl $hwlen pushl $hwstring pushl $1 # stdout call _write addl $4 * 3, %esp pushl $0 # EX_OK call _exit j@uriah 118% as -o hw.o hw.s j@uriah 119% ld -o helloworld -e entry -Bstatic hw.o -lc j@uriah 120% ./helloworld Hello, world! (I think the -e entry is not strictly necessary if your program cares to jump into its entry point. Mine doesn't, without the -e entry, the "Hello world!\n" would have been executed as program code.) -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)