🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: gas and gcc

#153
From: Tauno Voipio
Date: Sat, 24 Nov 2001 18:51
65 lines
3525 bytes
"Martin Cote" <vlrcfmnw@videotron.ca> wrote in message
news:3BFDF24B.9E4D2F05@videotron.ca...
> 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...
>

1. You should not attempt to by-pass the libc and call the OS directly using
the software interrupt.

2. You cannot write into the code segment - it is a no-no! Move the
temporary data elsewhere. The standard way is to allocate the temp location
in the stack. Do not think of writing self-modifying code - it is a
hardware-protected impossibility.

My recommendation is to start the assembly language training without messing
first with the operating system.

An usable template for the assembler routine can be obtained by compiling
the corresponding routine skeleton with GCC using the -S switch.

Tauno Voipio
tauno voipio @ iki fi
Technical Details
Message-ID: <rMKL7.30$6W5.3075@read2.inet.fi>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail
References: <3BFDF24B.9E4D2F05@videotron.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f7d8d,c50bd0ec38019abd
X-Google-Attributes: gidf7d8d,public
X-Google-Thread: 114917,c50bd0ec38019abd
X-Google-Attributes: gid114917,public
X-Google-Thread: f65d0,c50bd0ec38019abd
X-Google-Attributes: gidf65d0,public
X-Google-ArrivalTime: 2001-11-24 10:57:51 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail
From: "Tauno Voipio" <tauno.voipio@iki.fi.SPAMBAIT_REMOVE>
Newsgroups: comp.lang.asm.x86,alt.lang.asm,gnu.gcc
Subject: Re: gas and gcc
Approved: CLAX86 Moderators <ccrayne@crayne.org>
Date: Sat, 24 Nov 2001 18:51:40 +0000 (UTC)
Organization: Sonera corp Internet services
Message-ID: <rMKL7.30$6W5.3075@read2.inet.fi>
Sender: clax86@odin.asgard
References: <3BFDF24B.9E4D2F05@videotron.ca>
Mime-Version: 1.0
Content-Type: text/plain;
        charset="iso-8859-1"
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: 1799;1;2769514710
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
X-Complaints-To: newsabuse@supernews.com
Lines: 66