delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/03/15/11:23:49

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_40
X-Spam-Check-By: sourceware.org
Message-ID: <SNT124-W268B75B0F1F523EE6A9847992E0@phx.gbl>
From: Brandon Chase <tapedispenser7 AT hotmail DOT com>
To: <cygwin AT cygwin DOT com>
Subject: Assembly language exit() syscall does not return correct value
Date: Mon, 15 Mar 2010 16:23:39 +0000
MIME-Version: 1.0
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

The following program is supposed to return a value of 222 when echo $?=20
run, but I get 127 every time, no matter what I change. I have looked=20
around but cannot seem to find out if this is an error or a=20
cygwin-specific value.

----------------------------------------------------------
#PURPOSE:
 This program finds the maximum number of a
# set of data items.
#
#VARIABLES:
 The registers have the following uses:
#
# %edi - Holds the index
 of the data item being examined
# %ebx - Largest data item found
#
 %eax - Current data item
#
# The following memory locations are=20
used:
#
# data_items - contains the item data. A 0 is used
# to
 terminate the data
#
.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 _start

_start:
movl $0,=20
%edi=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 =A0 =A0 =A0 =A0=A0 # move 0 into the index register
movl
 data_items(,%edi,4), %eax=A0=A0=A0=A0=A0=A0=A0=A0 # load the first byte of=
 data
movl
 %eax, %ebx=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 # since this is the first item,=20
%eax is
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # the=20
biggest
start_loop:=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # start loop

cmpl
 $0, %eax=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 # check to see if we=92ve hit the=20
end
je loop_exit
incl %edi=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #=20
load next value
movl data_items(,%edi,4), %eax
cmpl %ebx,=20
%eax=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0 # compare values
jle=20
start_loop=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # jump to loop beginning if=20
the new
# one isn=92t bigger
movl %eax,=20
%ebx=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0 # move the value as the largest
32

jmp
 start_loop=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 # jump to loop beginning
loop_exit:

#
 %ebx is the status code for the exit system call
# and it already=20
has the maximum number

movl $1, %eax =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 #=
1 is the exit() syscall

-----------

$>
 as maximum.s -o maximum.o
$> ld maximum.o -o maximum
$>./maximum
$>echo
 $?
127











=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20

=20=09=09=20=09=20=20=20=09=09=20=20
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=3DPID27925::T:WLMTAGL:O=
N:WL:en-US:WM_HMP:032010_1

--
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