* 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
* Re: prime numbers
2005-07-13 22:40 prime numbers Paul Irofti
@ 2005-07-14 0:14 ` Frank Kotler
2005-07-14 2:21 ` Paul Irofti
0 siblings, 1 reply; 5+ messages in thread
From: Frank Kotler @ 2005-07-14 0:14 UTC (permalink / raw)
To: Paul Irofti; +Cc: linux-assembly
Paul Irofti wrote:
...
> sieve.o(.text+0x1):sieve.s:20: relocation truncated to fit: R_386_8 .data
...
> movb $test, %dl
Pretty sure you want "movb test, %dl" - "$test" indicates that you're
trying to move the *address* of your "test" variable (not the contents)
into %dl... and it won't fit! (...etc.)
Best,
Frank
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: prime numbers
2005-07-14 0:14 ` Frank Kotler
@ 2005-07-14 2:21 ` Paul Irofti
2005-07-14 2:51 ` Frank Kotler
0 siblings, 1 reply; 5+ messages in thread
From: Paul Irofti @ 2005-07-14 2:21 UTC (permalink / raw)
To: Frank Kotler; +Cc: linux-assembly
Frank Kotler wrote:
> Paul Irofti wrote:
>
> ...
>
>> sieve.o(.text+0x1):sieve.s:20: relocation truncated to fit: R_386_8
>> .data
>
>
> ...
>
>> movb $test, %dl
>
>
> Pretty sure you want "movb test, %dl" - "$test" indicates that you're
> trying to move the *address* of your "test" variable (not the
> contents) into %dl... and it won't fit! (...etc.)
>
> Best,
> Frank
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-assembly" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
ok, so than what's the diffrence between:
a) movb $test, %al
b) movb test, %al
c) movb (test), %al
c) movb ($test), %al #if this exists!
and how come when i access kernel ops i use $<oper>
i.e. movl $__NR_write, %eax #i actually append the address 1?! not
put the value 1?!
these are very confusing stuff for me. and i would greatly apreciate it
if explained! thanks a lot Frank!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: prime numbers
2005-07-14 2:21 ` Paul Irofti
@ 2005-07-14 2:51 ` Frank Kotler
2005-07-14 3:02 ` Paul Irofti
0 siblings, 1 reply; 5+ messages in thread
From: Frank Kotler @ 2005-07-14 2:51 UTC (permalink / raw)
To: Paul Irofti; +Cc: linux-assembly
Paul Irofti wrote:
...
> ok, so than what's the diffrence between:
> a) movb $test, %al
> b) movb test, %al
> c) movb (test), %al
> c) movb ($test), %al #if this exists!
Hmmm, I'm actually Nasmist, not an as user, but...
> and how come when i access kernel ops i use $<oper>
>
> i.e. movl $__NR_write, %eax #i actually append the address 1?! not
> put the value 1?!
I perhaps shouldn't have said "address"... As I understand it, the '$'
indicates an "immediate" value. "movl $4, %eax" (or $__NR_write) moves
the value 4 into %eax. "movl 4, %eax" would move the contents of address
0x00000004 into %eax - except that it segfaults because 0x00000004 isn't
in "your" address space.
Maybe an actual (G)as user can clarify it better. It *is* confusing - if
it were easy, everybody'd be doing it! :)
Best,
Frank
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: prime numbers
2005-07-14 2:51 ` Frank Kotler
@ 2005-07-14 3:02 ` Paul Irofti
0 siblings, 0 replies; 5+ messages in thread
From: Paul Irofti @ 2005-07-14 3:02 UTC (permalink / raw)
To: Frank Kotler; +Cc: linux-assembly
Frank Kotler wrote:
> Paul Irofti wrote:
>
> ...
>
>> ok, so than what's the diffrence between:
>> a) movb $test, %al
>> b) movb test, %al
>> c) movb (test), %al
>> c) movb ($test), %al #if this exists!
>
>
> Hmmm, I'm actually Nasmist, not an as user, but...
>
>> and how come when i access kernel ops i use $<oper>
>>
>> i.e. movl $__NR_write, %eax #i actually append the address 1?! not
>> put the value 1?!
>
>
> I perhaps shouldn't have said "address"... As I understand it, the '$'
> indicates an "immediate" value. "movl $4, %eax" (or $__NR_write) moves
> the value 4 into %eax. "movl 4, %eax" would move the contents of
> address 0x00000004 into %eax - except that it segfaults because
> 0x00000004 isn't in "your" address space.
>
> Maybe an actual (G)as user can clarify it better. It *is* confusing -
> if it were easy, everybody'd be doing it! :)
>
> Best,
> Frank
>
>
thanks man!
i had the same problems with syntax and address/value access in MASM
when i started, now, i see myself hitting the same spot in the *nix
world of assembly:))
well, i'm blown off, it's 6am here, i need some sleep, hopefully someone
will make my morning..eh! afternoon... sweeter with a short lesson on
the issue!
bye!
^ 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).