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

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Mon, 15 Mar 2010 12:56:45 -0400
From: Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Assembly language exit() syscall does not return correct value
Message-ID: <20100315165645.GA30887@ednor.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <SNT124-W268B75B0F1F523EE6A9847992E0 AT phx DOT gbl>
MIME-Version: 1.0
In-Reply-To: <SNT124-W268B75B0F1F523EE6A9847992E0@phx.gbl>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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 Mon, Mar 15, 2010 at 04:23:39PM +0000, Brandon Chase wrote:
>
>The following program is supposed to return a value of 222 when echo $? 
>run, but I get 127 every time, no matter what I change. I have looked 
>around but cannot seem to find out if this is an error or a 
>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 
>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, 
>%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

I cleaned this up to remove the odd wrapping and strange
characters:

	.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, %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

If, in theory, I got this right then, on linux it SEGVs.  I would
not expect anything different on Cygwin.  It seems like you need
to actually call exit() if you want this to exit.

cgf

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