Page 1 of 1

compiling at assembly level using cygwin

Posted: Sun Jan 01, 2012 10:49 pm
by sithlord
Hi,

The following code is meant to find the highest value from a list of integers, but when (using cygwin) but after assembly and linkin, "echo $?" only returns 127 and not the 222 as expected. I dont think it is an error but i'm also not sure how to go about it.

Code: Select all


#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 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 the next value
 movl data_items(,%edi,4), %eax
 cmpl %ebx, %eax		#compare values
 jle start_loop			#jump to loop beginning if the new
						#one isnt bigger
movl %eax, %ebx			#move the value as the largest
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() sys call

int $0x80


Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 2:37 am
by Brynet-Inc
I don't think you understand what Cygwin is, but that's the least of your problems.

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 8:38 pm
by sithlord
thanks for the reply. could you elaborate on where i've gone wrong?

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 9:03 pm
by Jvac
Cygwin is is a Unix-like environment and command-line interface for Microsoft Windows not an Assembler see here. For assemblers see the Wiki.

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 10:55 pm
by sithlord
hi,

thanks for the help. i got that all sorted out but for learning purposes would you know how i could get it to run on win32? or was it meant for unix system (frankly i'm stumped, the code file had a .s extension which i have failed to get much information on though i know its assembly language)

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 10:57 pm
by gerryg400
Why not ask the person who gave you the code ?

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 11:03 pm
by sithlord
i got it from a book (programming ground up) and the books forum wasnt quite helpful (several other readers had the same questions as i but got no answers). i have nasm and mingw and managed to generate an object file which i converted to an executable but it crashes when i try to run it. i'm new to assembly languages so i have to ask, should i just start a clean slate stick to regular asm and c tutorials?

Re: compiling at assembly level using cygwin

Posted: Mon Jan 02, 2012 11:09 pm
by gerryg400
"Programming from the Ground Up" is a book on Linux assembly language programming. On page 3 of that book it says
This book teaches assembly language for x86 processors and the GNU/Linux operating system. Therefore we will be giving all of the examples using the GNU/Linux standard GCC tool set. If you are not familiar with GNU/Linux and the GCC tool set, they will be described shortly. If you are new to Linux, you should check out the guide available at http://rute.sourceforge.net/

Re: compiling at assembly level using cygwin

Posted: Tue Jan 03, 2012 5:42 pm
by Jvac
Also see GCC Wiki page will help if you using Cygwin.

Edit: and cross-compilation environment