🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.asm.x86
Article #151

gas and gcc

#151
From: Martin Cote
Date: Sat, 24 Nov 2001 00:16
47 lines
2530 bytes
Hi,

I'm trying to write some C modules in assembly.  I'm using 'gcc' and
'as' under linux.  I'm trying some test to 'get the feel' of this hybrid
programming.  I'm trying a simple 'write_char' function that display the
char passed in parameter on the screen.  Here's my source code :
extern write_char(char);
----------------------------------
..globl write_char

write_char:
 pushl %ebp
 movl  %esp,%ebp
 movl  $4,%eax
 xorl  %ebx,%ebx
 incl  %ebx
 movl  4(%esp),%ecx
 movl  %ecx,char
 leal  char,%ecx
 xorl  %edx,%edx
 incl  %edx
 int   $0x80
 leave
 ret

char: .byte 0,0,0,0
----------------------------------

And the C main :

----------------------------------
extern write_char(char);

int main() {
  write_char(97);
  return 0;
}
----------------------------------

The problem is that it get a 'core dump' ;)
There is something that I did not undersand in the way to pass
parameters to a C function (with the %esp register).

If anyone can help, I would be really grantful...

Thank you very much
Martin
Technical Details
Message-ID: <3BFDF24B.9E4D2F05@videotron.ca>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f7d8d,c50bd0ec38019abd,start
X-Google-Attributes: gidf7d8d,public
X-Google-Thread: 114917,c50bd0ec38019abd,start
X-Google-Attributes: gid114917,public
X-Google-Thread: f65d0,c50bd0ec38019abd,start
X-Google-Attributes: gidf65d0,public
X-Google-ArrivalTime: 2001-11-23 16:57:53 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail
From: Martin Cote <vlrcfmnw@videotron.ca>
Newsgroups: comp.lang.asm.x86,alt.lang.asm,gnu.gcc
Subject: gas and gcc
Approved: CLAX86 Moderators <ccrayne@crayne.org>
Date: Sat, 24 Nov 2001 00:16:21 +0000 (UTC)
Organization: crayne.org
Message-ID: <3BFDF24B.9E4D2F05@videotron.ca>
Sender: clax86@odin.asgard
Reply-To: mentalray@videotron.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-CLAX86-Policy: http://www.pacificsites.com/~ccrayne/clax86.html
X-CLAX86-Faq: http://www2.dgsys.com/~raymoon/x86faqs.html
X-CLAX86-Info-1: Send submissions to             comp-lang-asm-x86@moderators.isc.org
X-CLAX86-Info-2: Send technical complaints to    ccrayne@crayne.org
X-CLAX86-Info-3: Send complaints about policy to ccrayne@crayne.org
X-Comment: moderators do not necessarily agree or disagree with this article.
X-RocketRCL: 1013;1;2974110035
X-Accept-Language: en
X-Complaints-To: newsabuse@supernews.com
Lines: 48