delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/03/17/23:21:45

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4BA1AE94.1030600@gmail.com>
Date: Thu, 18 Mar 2010 04:39:48 +0000
From: Dave Korn <dave DOT korn DOT cygwin AT googlemail DOT com>
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Assembly language exit() syscall does not return correct value
References: <SNT124-W2474B6AD4E766F69DD69EE992D0 AT phx DOT gbl> <98091D8BAF39E746A7D3E618C948528D279C5141 AT DF-M14-02 DOT exchange DOT corp DOT microsoft DOT com>
In-Reply-To: <98091D8BAF39E746A7D3E618C948528D279C5141@DF-M14-02.exchange.corp.microsoft.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 16/03/2010 17:08, Stephan Mueller wrote:
> Brandon Chase wrote:
> " DaveK wrote:

> " "   Brandon, Cygwin isn't compatible with Linux at the assembler-code level, 

> " So I cannot compile assembly language with Cygwin? Do I need a linux shell?
> 
> No, that's not what anyone said.  You can use the assembler on Cygwin to generate
> binaries that run on Cygwin (which is I think what you're looking for), but your
> assembly source code won't work as is -- you will need to make changes of the
> sort that DaveK and cgf state in the paragraphs above.

  Exactly.  Like so, for example:

> $ cat max.s
>         .section .data
> 
> data_items: #These are the data items
>         .long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
> 
> .section .text
> 
> .globl _main
> 
> _main: movl $0, %edi                    # move 0 into the index register
>         movl data_items(,%edi,4), %eax  # load the first byte of data
>         movl %eax, %ebx                 # since this is the first item, %eax is
>                                         # the biggest
> start_loop:                             # start loop
>         cmpl $0, %eax                   # check to see if we've hit the end
>         je loop_exit
>         incl %edi                       # load next value
>         movl data_items(,%edi,4), %eax
>         cmpl %ebx, %eax                 # compare values
>         jle start_loop                  # jump to loop beginning if the new
>                                         # one isn't bigger
>         movl %eax, %ebx                 # move the value as the largest 32
> 
>         jmp start_loop                  # jump to loop beginning
> loop_exit:
> # %ebx is the status code for the exit system call
> # and it already has the maximum number
> #       movl $1, %eax                   #1 is the exit() syscall
> # But we don't have linux syscalls!  Instead, we do
> # a c-style call to the exit() function by pushing it
> # onto the stack!
>         push %ebx
>         call    _exit
> # won't return.
> 
> $ gcc max.s -o max.exe
> 
> $ ./max.exe ; echo $?
> 222
> 
> $

  Note use of the gcc driver to compile it, rather than invoking the assembler
and linker directly, in order to let it get all the C runtime support linked
in correctly.

    cheers,
      DaveK


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019