linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* prime numbers
@ 2005-07-13 22:40 Paul Irofti
  2005-07-14  0:14 ` Frank Kotler
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Irofti @ 2005-07-13 22:40 UTC (permalink / raw)
  To: linux-assembly

this is an exercies i set out to do in order to familiarise my self with 
linux and AT&T
assembly syntax.

i worked a lot and read a lot before figureing out how each operator 
gets its paramaters and such...

the code doesn't compile with the following errors:

# as -gstabs sieve.s -o sieve.o
# gcc sieve.o -o sieve
sieve.o(.text+0x1):sieve.s:20: relocation truncated to fit: R_386_8 .data
sieve.o(.text+0xc):sieve.s:24: relocation truncated to fit: R_386_16 .data
sieve.o(.text+0x19):sieve.s:32: relocation truncated to fit: R_386_8 .data
sieve.o(.text+0x1b):sieve.s:33: relocation truncated to fit: R_386_8 .data
sieve.o(.text+0x2d):sieve.s:43: relocation truncated to fit: R_386_8 .data
sieve.o(.text+0x39):sieve.s:50: relocation truncated to fit: R_386_8 .data
collect2: ld returned 1 exit status

the source code is:

# assembly code for the calculation of the primes numbers in the range of [2-100]
# the code brute forces the numbers out, no formulas are taken in consideration

*.include* "defines.h"		#system call numbers are stored here (i.e. __NR_<oper> = number)

*.global* main

*.data*

sieve:	
	*.byte* 4
test:
	*.byte* 1

*.text*

main:
	
loop:	
	movb $test, %dl
	incb %dl		#increase test
	movb %dl, (test)
	
	movw $sieve, %ax	#prepare for divb: move sieve in ax
	divb %dl		#div ax by dl
	
	xor %cx, %cx		#clear cx
	movb %ah, %cl		#move rest in cx
	
	jcxz next		#test if rest is 0 and increase if so
	
	movb $sieve, %al
	movb $test, %bl
	cmpb %al, %bl		#else test if "test" has reached sieve
	
	jnz loop		#if not go back and div by new test value
	
				
print:	movl $__NR_write, %eax  #else print the prime
	movl $1, %ebx		#STDOUT is $1
	xor %ecx, %ecx
	
	movb $sieve, %cl
	addb $30, %cl		#make ascii out of int
	
	movl $16,%edx		#buffer size
	int $0x80
	
next:	
	movb $sieve, %cl
	incb %cl		#increase sieve
	movb %cl, (sieve)
	
	movb $100, %al
	cmpb %al, %cl		#test if limit is reached
	jz exit
			
	movb $1, %al		#if not start again with a new sieve and test = 1
	movb %al, (test)
	
	jmp loop
	
exit:	movl $0, %eax
	ret
	

please send me any critique and advices you can, i really want to make 
the complete switch from MASM to GAS as soon as possible....

cheers!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-07-14  3:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-13 22:40 prime numbers Paul Irofti
2005-07-14  0:14 ` Frank Kotler
2005-07-14  2:21   ` Paul Irofti
2005-07-14  2:51     ` Frank Kotler
2005-07-14  3:02       ` Paul Irofti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).