反汇编的.s文件在nasm中不可接受的语法是什么? [英] What syntax does a disassembled .s file is not acceptable in nasm?

查看:539
本文介绍了反汇编的.s文件在nasm中不可接受的语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码是一个C程序(冒泡排序),反汇编成汇编。如果我将它放在.asm文件中并使用nasm进行组装,如何运行以下代码?如果您知道需要更改什么,请说出要更改的内容。例如,我明白nasm不会接受 DWORD PTR ,但我没有找到相应的解决方法。谢谢

  .filesort.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 PT R [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,。-s
.identGCC:(Ubuntu / Linaro 4.6.3-1ubuntu5)4.6.3
.section .note.GNU-stack,@ progbits


解决方案

只要删除 PTR $ b <
$ b p $ p> ; 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文档。阅读。特别是这些部分:

$ ul

  • 2.2.2 NASM需要内存引用的方括号


  • 2.2.3 NASM不存储变量类型



  • This code is a C program (bubble sort) disassembled into assembly. How can I make the following code run if I put it in a .asm file and use nasm to assemble? If you know what needs changing, please say what to change it to. For instance I understand that nasm won't accept DWORD PTR, but I haven't found out what to do instead. Thanks

    .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
    

    解决方案

    Just remove PTR and all nonsensical .somethings.

    This assembles just fine:

    ; 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
    

    Command:

    nasm gas-nasm-sort.asm -f bin -o gas-nasm-sort.bin
    

    But again, there's NASM documentation. Read it. In particular these sections:

    • 2.2.2 NASM Requires Square Brackets For Memory References

    • 2.2.3 NASM Doesn't Store Variable Types

    这篇关于反汇编的.s文件在nasm中不可接受的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆