compiling at assembly level using cygwin

Programming, for all ages and all languages.
Post Reply
sithlord
Posts: 5
Joined: Wed Dec 21, 2011 6:23 pm

compiling at assembly level using cygwin

Post 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

User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: compiling at assembly level using cygwin

Post by Brynet-Inc »

I don't think you understand what Cygwin is, but that's the least of your problems.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
sithlord
Posts: 5
Joined: Wed Dec 21, 2011 6:23 pm

Re: compiling at assembly level using cygwin

Post by sithlord »

thanks for the reply. could you elaborate on where i've gone wrong?
User avatar
Jvac
Member
Member
Posts: 58
Joined: Fri Mar 11, 2011 9:51 pm
Location: Bronx, NY

Re: compiling at assembly level using cygwin

Post 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.
"The best way to prepare for programming is to write programs, and
to study great programs that other people have written." - Bill Gates


Think beyond Windows ReactOS®
sithlord
Posts: 5
Joined: Wed Dec 21, 2011 6:23 pm

Re: compiling at assembly level using cygwin

Post 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)
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: compiling at assembly level using cygwin

Post by gerryg400 »

Why not ask the person who gave you the code ?
If a trainstation is where trains stop, what is a workstation ?
sithlord
Posts: 5
Joined: Wed Dec 21, 2011 6:23 pm

Re: compiling at assembly level using cygwin

Post 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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: compiling at assembly level using cygwin

Post 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/
If a trainstation is where trains stop, what is a workstation ?
User avatar
Jvac
Member
Member
Posts: 58
Joined: Fri Mar 11, 2011 9:51 pm
Location: Bronx, NY

Re: compiling at assembly level using cygwin

Post by Jvac »

Also see GCC Wiki page will help if you using Cygwin.

Edit: and cross-compilation environment
"The best way to prepare for programming is to write programs, and
to study great programs that other people have written." - Bill Gates


Think beyond Windows ReactOS®
Post Reply