PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Assembler-Frage



SeeksTheMoon
09-03-2003, 10:02
Ich habe unter Windows mal ein paar Assemblerprogramme geschrieben. Jetzt will ich die unter Linux ans Laufen bringen, z.B. das HelloWorld:



Text SEGMENT
hallo DB "Hello world!$"
Text ENDS

Stapel SEGMENT stack
DW 128 dup (?)

Prog SEGMENT
ASSUME cs:Prog, ds: Text, ss:Stapel
Start:
lea dx, hallo
int 21h
int 4ch
Prog ENDS

END Start


Wenn ich das Programm mit "as hellowor.asm" übersetze, spuckt er folgenden Fehler aus:


hellowor.asm: Assembler messages:
hellowor.asm:1: Error: no such instruction: `text SEGMENT'
hellowor.asm:2: Error: no such instruction: `hallo DB "Hello world!$"'
hellowor.asm:3: Error: no such instruction: `text ENDS'
hellowor.asm:5: Error: no such instruction: `stapel SEGMENT stack'
hellowor.asm:6: Error: no such instruction: `dw 128 dup (?)'
hellowor.asm:8: Error: no such instruction: `prog SEGMENT'
hellowor.asm:9: Error: no such instruction: `assume cs:Prog,ds:Text,ss:Stapel'
hellowor.asm:11: Error: too many memory references for `lea'
hellowor.asm:12: Error: junk `h' after expression
hellowor.asm:12: Error: suffix or operands invalid for `int'
hellowor.asm:13: Error: junk `ch' after expression
hellowor.asm:13: Error: suffix or operands invalid for `int'
hellowor.asm:14: Error: no such instruction: `prog ENDS'
hellowor.asm:16: Error: no such instruction: `end Start'


Ich habe mir die Manpage vom as angesehen, kann da jetzt aber keine Besonderheiten entdecken. Da steht zwar, dass der GNU as eigentlich für den gcc geschrieben wurde, aber dass er auch alles andere assembliert.
Jetzt habe ich die Frage, ob Assemblerprogramme unter Linux völlig anders aussehen müssen als unter DOS/Windows oder ob der GNU as überhaupt das richtige Werkzeug ist (welchen Assembler soll ich sonst nehmen?).
Ich habe auch andere Quellcodes ausprobiert. Der meckert sogar Kommentarzeilen mit "no such instruction" an.

phate
09-03-2003, 10:27
Moin SeeksTheMoon,

ich hatte im Rahmen vonner Vorlesung mal ähnliche Probleme. Alle Programme mit TASM auf Windows entwickelt und als ich die dann mit NASM auf Linux testen wollte, bekam ich in etwa die selben Resultate wie Du.

Der Grund liegt in der unterschiedlichen Syntax, die die jeweiligen Assembler verwenden.

Hab gerade mal gegoogelt und folgendes gefunden


NASM gibt es für viele Betriebsysteme, die Syntax ist eine etwas
abgewandelte Intel-Standard-x86-Assemblersyntax.

MASM/TASM halten sich an die Intel-Standardversion, GAS dagegen
orientiert sich an der Syntax der für die 68..er CPU gemachten
Assembler.

und im Assembler HOWTO unter

http://www.ldp.at/HOWTO/Assembly-HOWTO/gas.html

findet sich folgendes


Because GAS was invented to support a 32-bit unix compiler, it uses standard AT&T syntax, which resembles a lot the syntax for standard m68k assemblers, and is standard in the UNIX world. This syntax is neither worse, nor better than the Intel syntax. It's just different.

...

Good news are that starting from binutils 2.10 release, GAS supports Intel syntax too. It can be triggered with .intel_syntax directive. Unfortunately this mode is not documented (yet?) in the official binutils manual, so if you want to use it, try to examine http://home.snafu.de/phpr/lhpas86.html.gz, which is an extract from AMD 64bit port of binutils 2.11.

Ich habs dann sein lassen ... ;)

Linuxexplorer
09-03-2003, 10:28
Hi

Das Assemblerprogram, dass du unter Windows geschrieben hasst, ist füt tasm/masm. Der as hat eine völlig andere Syntyx (AT&T - Style, tasm/masn haben Intel-Style)

Ein HelloWorld müsste mi as so aussehen:

.data # section declaration

msg:
.string "Hello, world!\n" # our dear string
msgend:
.equ len, msgend - msg # length of our dear string

.text # section declaration

# we must export the entry point to the ELF linker or
.global _start # loader. They conventionally recognize _start as their
# entry point. Use ld -e foo to override the default.

_start:

# write our string to stdout

movl $4,%eax # system call number (sys_write)
movl $1,%ebx # first argument: file handle (stdout)
movl $msg,%ecx # second argument: pointer to message to write
movl $len,%edx # third argument: message length
int $0x80 # call kernel

# and exit

movl $1,%eax # system call number (sys_exit)
xorl %ebx,%ebx # first syscall argument: exit code
int $0x80 # call kernel

Eigentlich benützt man den nasm unter Linux: Hier HelloWorld:

section .text
global _start ;must be declared for linker (ld)

msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string

_start: ;tell linker entry point

mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel


MFG: Linuxexplorer

SeeksTheMoon
09-03-2003, 14:18
Also dürfte NASM der beste Assembler für mich sein, wenn ich keine andere Syntax lernen will. MASM ist ja von MS und TASM ist nur Shareware.

Mit der .intel_syntax im gas das bekomme ich nicht gebacken. Wo müsste man das angeben? In der manpage und der online-Doku steht nur, dass es solche Direktiven gibt, aber nicht wie man sie benutzt (und die intel_syntax ist tatsächlich nicht dokumentiert)

Hauptmann
30-03-2003, 18:10
Hi

tasm ist shareware

dann aber ziemlich lange

ich nutze nähmlich TASM schon sehr lange

und von der offizielen Borland Site gezogen

SeeksTheMoon
01-04-2003, 10:50
Wo gibt es denn tasm? Ich hab auf der Borlandseite nichts gefunden, nur Java und C/C++ Programme.
Eine IDE mit dem Namen hab ich gefunden und der Autor der IDE verlinkt für tasm auf die Borlandseite, aber das wird mit einem 404 quittiert....