Gcc 在nasm中,反汇编的.s文件不可接受的语法是什么?

Gcc 在nasm中,反汇编的.s文件不可接受的语法是什么?,gcc,assembly,syntax,nasm,Gcc,Assembly,Syntax,Nasm,这段代码是一个C程序(气泡排序)分解成汇编。如果我将以下代码放在.asm文件中并使用nasm进行汇编,如何使其运行?如果您知道需要更改的内容,请说出要更改的内容。例如,我知道nasm不会接受DWORD PTR,但我还不知道该怎么做。谢谢 .file "sort.c" .intel_syntax noprefix .text .globl sort .type sort, @function sort: .LFB0: .cfi_startproc push rbp

这段代码是一个C程序(气泡排序)分解成汇编。如果我将以下代码放在.asm文件中并使用nasm进行汇编,如何使其运行?如果您知道需要更改的内容,请说出要更改的内容。例如,我知道nasm不会接受DWORD PTR,但我还不知道该怎么做。谢谢

.file   "sort.c" .intel_syntax noprefix .text .globl 
sort .type   sort, @function
sort: .LFB0:
    .cfi_startproc
    push    rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    mov rbp, rsp
    .cfi_def_cfa_register 6
    mov QWORD PTR [rbp-24], rdi
    mov DWORD PTR [rbp-28], esi
    mov DWORD PTR [rbp-12], 0
    jmp .L2
.L6:
    mov DWORD PTR [rbp-8], 0
    jmp .L3
.L5:
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rax]
    mov eax, DWORD PTR [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov eax, DWORD PTR [rax]
    cmp edx, eax
    jle .L4
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov eax, DWORD PTR [rax]
    mov DWORD PTR [rbp-4], eax
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rbp-8]
    movsx   rdx, edx
    add rdx, 1
    sal rdx, 2
    add rdx, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rdx]
    mov DWORD PTR [rax], edx
    mov eax, DWORD PTR [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rbp-4]
    mov DWORD PTR [rax], edx
.L4:
    add DWORD PTR [rbp-8], 1
.L3:
    mov eax, DWORD PTR [rbp-28]
    sub eax, 1
    sub eax, DWORD PTR [rbp-12]
    cmp eax, DWORD PTR [rbp-8]
    jg  .L5
    add DWORD PTR [rbp-12], 1
.L2:
    mov eax, DWORD PTR [rbp-28]
    sub eax, 1
    cmp eax, DWORD PTR [rbp-12]
    jg  .L6
    pop rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   sort, .-sort
    .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
    .section    .note.GNU-stack,"",@progbits

只需删除
PTR
和所有无意义的
。一些东西

这个组合很好:

; file: gas-nasm-sort.asm
bits 64

sort:
push rbp
mov rbp, rsp
mov QWORD [rbp-24], rdi
mov DWORD [rbp-28], esi
mov DWORD [rbp-12], 0
jmp .L2

.L6:
mov DWORD [rbp-8], 0
jmp .L3

.L5:
mov eax, DWORD [rbp-8]
cdqe
sal rax, 2
add rax, QWORD [rbp-24]
mov edx, DWORD [rax]
mov eax, DWORD [rbp-8]
cdqe
add rax, 1
sal rax, 2
add rax, QWORD [rbp-24]
mov eax, DWORD [rax]
cmp edx, eax
jle .L4
mov eax, DWORD [rbp-8]
cdqe
sal rax, 2
add rax, QWORD [rbp-24]
mov eax, DWORD [rax]
mov DWORD [rbp-4], eax
mov eax, DWORD [rbp-8]
cdqe
sal rax, 2
add rax, QWORD [rbp-24]
mov edx, DWORD [rbp-8]
movsx rdx, edx
add rdx, 1
sal rdx, 2
add rdx, QWORD [rbp-24]
mov edx, DWORD [rdx]
mov DWORD [rax], edx
mov eax, DWORD [rbp-8]
cdqe
add rax, 1
sal rax, 2
add rax, QWORD [rbp-24]
mov edx, DWORD [rbp-4]
mov DWORD [rax], edx

.L4:
add DWORD [rbp-8], 1

.L3:
mov eax, DWORD [rbp-28]
sub eax, 1
sub eax, DWORD [rbp-12]
cmp eax, DWORD [rbp-8]
jg .L5
add DWORD [rbp-12], 1

.L2:
mov eax, DWORD [rbp-28]
sub eax, 1
cmp eax, DWORD [rbp-12]
jg .L6
pop rbp
ret
命令:

nasm gas-nasm-sort.asm -f bin -o gas-nasm-sort.bin
但是,还有NASM文档。读一下。特别是这些章节:

  • 2.2.2 NASM要求使用方括号表示内存引用

  • 2.2.3 NASM不存储变量类型


因为gcc专门为GNU汇编程序生成汇编。这包括指令、操作码语法、标签等。谢谢。我只是担心会把事情搞砸。我去看看。