私は64ビットUbuntuを使用していて、NASMで.asmファイルを実行しようとしています。しかし、次のコードを実行しようとすると、このエラーが返されます。何イムがやろうとすると、ソース $ nasm -f elf hello.asm
からオブジェクトファイルをコンパイル(またはアセンブル)で実行可能ファイルを構築し、その後、後のリンカにUbuntuのNASMで.asmファイルを実行しようとしたときにエラーが発生しました
$ ld -s -o hello hello.o
これを呼び出すことによってhello.o
は、オブジェクトファイルから実行ファイル自体を生産しているファイルを作成しています最終的にhello実行可能ファイルをビルドします。
私はこのチュートリアルに以下のよhttp://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html
エラー:入力ファイル `hello.oの
のi386アーキテクチャはi386のと互換性がありません:x86-64の出力
コード:
section .data ;section declaration
msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string
section .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
mov edx,len ;third argument: message length
mov ecx,msg ;second argument: pointer to message to write
mov ebx,1 ;first argument: file handle (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
;and exit
mov ebx,0 ;first syscall argument: exit code
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
@psyhclo:これは機能しますか? –
これは本当に正しいアプローチではありません.OPが書いているアセンブリも修正する必要があるからです(たとえば、 '%rax'、'%rbx'の上位32ビットをシステムの前にクリアする必要がありますコール)。 – caf
はい、@caf、そうかもしれません。私自身は、64ビットを実行しているので、コードを変更する方が好きですが、32ビットの実行ファイルを作成する方が望ましい場合があります。おそらくあなたの答えは、おそらくチュートリアルのために行くための最良の方法ですので、物事を取得する最小限の努力のバージョンを提供します。だから+1。 – paxdiablo