Weet gcc echt hoe NASM Assembly moet worden uitgevoerd?

Dus ik heb een eenvoudig C-programma dat door de argumenten loopt die aan main zijn doorgegeven en vervolgens retourneert:

#include 

int main(int argc, char *argv[])
{
    int i;
    for(i = 0; i < argc; ++i) {
        fprintf(stdout, "%s\n", argv[i]);
    }
    return 0;
}

Ik wilde zien hoe gcc de assembly in NASM-formaat schreef. Ik keek naar de uitvoer in het .asm-bestEN en merkte op dat de syntax TASM was. Hieronder vindt u het make-bestEN en de uitvoer van gcc. Doe ik iets verkeerd of is het dat gcc geen echte NASM-syntaxis uitvoert?

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

EN

    .file   "main.c"
    .intel_syntax noprefix
    .section    .rodata
.LC0:
    .string "%s\n"
    .text
.globl main
    .type   main, @function
main:
    push    ebp
    mov ebp, esp
    EN 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

The errors on the commEN line are:

[[email protected] sENbox-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

What lead me to believe that this is TASM syntax was information posted at this link: http://rs1.szif.hu/~tomcat/win32/intro.txt

TASM coders usually have lexical difficulties with NASM because it lacks the "ptr" keyword used extensively in TASM.

TASM uses this:

mov al, byte ptr [ds:si] or mov ax, word ptr [ds:si] or mov eax, dword ptr [ds:si]

For NASM This simply translates into:

mov al, byte [ds:si] or mov ax, word [ds:si] or mov eax, dword [ds:si]

NASM allows these size keywords in many places, EN thus gives you a lot of control over the generated opcodes in a unifrom way, for example These are all valid:

push dword 123 jmp [ds: word 1234] ; these both specify the size of the offset jmp [ds: dword 1234] ; for tricky code when interfacing 32bit EN ; 16bit segments

it can get pretty hairy, but the important thing to remember is you can have all the control you need, when you want it.

3

1 antwoord

Intel-syntaxis betekent Intel-syntaxis, niet NASM-syntaxis. MASM- en TASM-syntaxes zijn gebaseerd op Intel Syntax, NASM-syntaxis wordt geïnspireerd door de syntaxis van Intel, maar is anders.

Welke gcc-uitgangen is eigenlijk gassyntaxis met behulp van Intel-syntaxis voor individuele instructies (Assembler-richtlijnen, labels et al. Gebruiken gasspecifieke syntaxis)

7
toegevoegd
Kent u boeken of online informatie over de syntaxis van gassen? Weet jij ook welke assembly-syntaxis de cl.exe-uitgangen van Microsoft zijn?
toegevoegd de auteur Matthew Hoggan, de bron
@MatthewHoggan: gassyntaxis wordt beschreven in de gashandleiding: sourceware.org/ binutils/docs-2.22/as/Syntax.html # Syntaxis , maar zoals ik al zei, individuele instructies zijn in Intel-syntaxis.
toegevoegd de auteur ninjalj, de bron