gccのを知っています。 .asmファイルの出力を調べて、構文がTASMであることに気づいた。以下はmakeファイルとgccからの出力です。私は何か間違っているのですか、それともgccが本当のNASM構文を出力しないのでしょうか?は本当にだから私はメインに渡される引数をループし、簡単なCプログラムを持って、その後返す方法に出力NASMアセンブリ
all: main
main: main.o
ld -o main main.o
main.o : main.c
gcc -S -masm=intel -o main.asm main.c
nasm -f elf -g -F stabs main.asm -l main.lst
と
.file "main.c"
.intel_syntax noprefix
.section .rodata
.LC0:
.string "%s\n"
.text
.globl main
.type main, @function
main:
push ebp
mov ebp, esp
and esp, -16
sub esp, 32
mov DWORD PTR [esp+28], 0
jmp .L2
.L3:
mov eax, DWORD PTR [esp+28]
sal eax, 2
add eax, DWORD PTR [ebp+12]
mov ecx, DWORD PTR [eax]
mov edx, OFFSET FLAT:.LC0
mov eax, DWORD PTR stdout
mov DWORD PTR [esp+8], ecx
mov DWORD PTR [esp+4], edx
mov DWORD PTR [esp], eax
call fprintf
add DWORD PTR [esp+28], 1
.L2:
mov eax, DWORD PTR [esp+28]
cmp eax, DWORD PTR [ebp+8]
jl .L3
mov eax, 0
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
.section .note.GNU-stack,"",@progbits
コマンドラインでのエラーは、次のとおりです。
[[email protected] sandbox-print_args]$ make
gcc -S -masm=intel -o main.asm main.c
nasm -f elf -g -F stabs main.asm -l main.lst
main.asm:1: error: attempt to define a local label before any non-local labels
main.asm:1: error: parser: instruction expected
main.asm:2: error: attempt to define a local label before any non-local labels
main.asm:2: error: parser: instruction expected
main.asm:3: error: attempt to define a local label before any non-local labels
main.asm:3: error: parser: instruction expected
main.asm:4: error: attempt to define a local label before any non-local labels
main.asm:5: error: attempt to define a local label before any non-local labels
main.asm:5: error: parser: instruction expected
main.asm:6: error: attempt to define a local label before any non-local labels
main.asm:7: error: attempt to define a local label before any non-local labels
main.asm:7: error: parser: instruction expected
main.asm:8: error: attempt to define a local label before any non-local labels
main.asm:8: error: parser: instruction expected
main.asm:14: error: comma, colon or end of line expected
main.asm:17: error: comma, colon or end of line expected
main.asm:19: error: comma, colon or end of line expected
main.asm:20: error: comma, colon or end of line expected
main.asm:21: error: comma, colon or end of line expected
main.asm:22: error: comma, colon or end of line expected
main.asm:23: error: comma, colon or end of line expected
main.asm:24: error: comma, colon or end of line expected
main.asm:25: error: comma, colon or end of line expected
main.asm:27: error: comma, colon or end of line expected
main.asm:29: error: comma, colon or end of line expected
main.asm:30: error: comma, colon or end of line expected
main.asm:35: error: parser: instruction expected
main.asm:36: error: parser: instruction expected
main.asm:37: error: parser: instruction expected
make: *** [main.o] Error 1
これはTASMの構文であると信じて私をリードし、どのような情報は、このリンクで投稿されました: http://rs1.szif.hu/~tomcat/win32/intro.txt
TASMコーダーは通常、TASMで広範に使用される "ptr"キーワードがないので、NASMで字句に問題があります。
のMOVら、バイトPTR [DS:SI]またはMOV斧、ワードPTR [DS:SI]またはMOVのEAX、 のDWORD PTR [DS:SI]
について
TASMこの使用しますNASMこれは単純に変換:
MOVら、バイト[DS:SI]またはMOV斧、単語[DS:SI]またはMOVのEAX、DWORD [DS:SI]
NASMは、これらのサイズのキーワードで可能多くの場所は、したがって、あなたに 制御の多くを与えるov生成されたオペコードをユニファイ・ウェイで表現すると、 の場合これらはすべて有効です。
push dword 123 jmp [ds:word 1234];これらは両方ともオフセットjmp [ds:dword 1234]のサイズ を指定します。複雑なコードの場合 32bitと のインターフェース。 16ビットセグメント
それはかなり毛むくじゃらすることができますが、覚えておくべき重要なことは、あなたが必要なときに必要なすべてのコントロールを持つことができることです。
を知っていますか?また、Microsoftのcl.exeが出力するアセンブリ構文について知っていますか? –
@MatthewHoggan:ガス構文はガスマニュアル(http://sourceware.org/binutils/docs-2.22/as/Syntax.html#Syntax)に記述されていますが、私が言ったように、個々の指示はIntelの構文になっています。 – ninjalj