From: Paul Irofti <bulibuta@gmail.com>
To: linux-assembly@vger.kernel.org
Subject: prime numbers
Date: Thu, 14 Jul 2005 01:40:24 +0300 [thread overview]
Message-ID: <42D59858.8060404@gmail.com> (raw)
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!
next reply other threads:[~2005-07-13 22:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-13 22:40 Paul Irofti [this message]
2005-07-14 0:14 ` prime numbers Frank Kotler
2005-07-14 2:21 ` Paul Irofti
2005-07-14 2:51 ` Frank Kotler
2005-07-14 3:02 ` Paul Irofti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42D59858.8060404@gmail.com \
--to=bulibuta@gmail.com \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).