2
すべてのアセンブリコードの例が32ビットLinux環境向けに書かれており、64ビットMacを使用している本を読んでいます。 _start
をstart
に変更した後、NASMで次のプログラムをコンパイルすることができました。しかし、私が実行可能ファイルを実行すると、それは私が期待する通りhello world
を印刷しません。 64ビットMacで動作するようにNASMにコンパイルするオプションがありますか?NASMを使用してx86_64環境用の32ビットアセンブリをコンパイルします
は私が試した:続い
nasm -f macho32 helloworld.asm
と
nasm -f macho helloworld.asm
:
ld helloworld.o -o helloworld
私のコードを次のとおりです。
section .data ; data segment
msg db "Hello, world!", 0x0a ; the string and newline char
section .text ; text segment
global start ; Default entry point for ELF linking
start:
; SYSCALL: write(1, msg, 14)
mov eax, 4 ; put 4 into eax, since write is syscall #4
mov ebx, 1 ; put 1 into ebx, since stdout is 1
mov ecx, msg ; put the address of the string into ecx
mov edx, 14 ; put 14 into edx, since our string is 14 bytes
int 0x80 ; Call the kernel to make the system call happen
; SYSCALL: exit(0)
mov eax, 1 ; put 1 into eax, since exit is syscall #1
mov ebx, 0 ; exit with success
int 0x80 ; do the syscall
'int 0x80'はOS/XでLinuxと同じように動作しません(システムコールは異なります)。 Linuxコードを真面目な点として使用することはお勧めできません。合理的な出発点はここにあります:https://filippo.io/making-system-calls-from-assembly-in-mac-os-x/ –
32ビットMac OS/X Oneのアセンブリ言語のチュートリアルが必要です。 -bit OS/Xコードは、64ビットOS/Xで動作します。真に64ビットのOS/Xコードを作成したいなら、 'int 0x80'を削除して' syscall'命令を使うことになります。これは 'int 0x80'とは異なります。呼び出し規約が異なり、システムコール番号が32ビットOS/Xコードと一致しません。 64ビットOS/Xコードを対象とするチュートリアルが必要です。また、NASMで '-f macho64'を使う必要があります。 –