2011-12-06 1 views
3

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ビットセグメント

それはかなり毛むくじゃらすることができますが、覚えておくべき重要なことは、あなたが必要なときに必要なすべてのコントロールを持つことができることです。

答えて

7

Intel構文は、NASM構文ではなくIntel構文を意味します。 MASM構文とTASM構文はIntel構文に基づいており、NASM構文はIntel構文から影響を受けますが、それは異なります。あなたは、任意の書籍やガス構文を扱うオンライン情報の個々の命令、インテルの構文を使用して、実際にガス構文であるGCCは何の出力

(アセンブラディレクティブ、ラベルらガス固有の構文を使用します)

+0

を知っていますか?また、Microsoftのcl.exeが出力するアセンブリ構文について知っていますか? –

+0

@MatthewHoggan:ガス構文はガスマニュアル(http://sourceware.org/binutils/docs-2.22/as/Syntax.html#Syntax)に記述されていますが、私が言ったように、個々の指示はIntelの構文になっています。 – ninjalj

関連する問題