【问题标题】:operation size not specified未指定操作大小
【发布时间】:2014-12-28 17:50:50
【问题描述】:

我对 32 位汇编有问题,在 linux 上使用 NASM 进行汇编。 这是我的插入排序实现

myInsertionSort:
push ebp
mov ebp, esp
push ebx
push esi
push edi
mov ecx, [ebp+12]   ;put len in ecx, our loop variable
mov eax, 1 ; size of one spot in array, one byte
mov ebx, 0
mov esi, [ebp+8] ; the array
loop loop_1
loop_1:
    cmp eax, ecx ; if we're done
    jge done_1 ; then done with loop
    push ecx ; we save len, because loop command decrements ecx
    mov ecx, [esi+eax] ; ecx now array[i]
    mov ebx, eax
    dec ebx ; ebx is now eax-1, number of times we should go through inner loop
    loop_2:
        cmp ebx, 0 ; we don't use loop to not affect ecx so we use ebx and compare it manually with 0
        jl done_2
        cmp [esi+ebx], ecx ;we see if array[ebx] os ecx so we can exit the loop
        jle done_2
        mov edx, esi
        add edx, ebx
        push [edx] ; pushing our array[ebx] *****************************
        add edx, eax
        pop [edx] ; poping the last one *********************************
        dec ebx ; decrementing the loop iterator
        jmp loop_2 ; looping again
    done_2:
        mov [esi+ebx+1], ecx
        inc eax ; incrementing iterator
        pop ecx ; len of array to compare now to eax and see if we're done
        jmp loop_1
done_1:
    pop edi
    pop esi
    pop ebx
    pop ebp ; we pop them in opposite to how we pushed (opposite order, it's the stack, LIFO)
    ret

现在...当我尝试使用 nasm 编译代码时,在 cmets 中包含星号的行中出现“未指定操作大小”的错误:P 这是基本的插入排序,我不确定可能出了什么问题。 请启发我。

【问题讨论】:

    标签: linux assembly nasm


    【解决方案1】:

    [edx] 的数据可以是任何东西,因此汇编器不知道它的大小。您必须指定要推送/弹出的数据的大小。例如,如果您想推送/弹出 dword(32 位),您可以这样写:

    push dword [edx]
    pop dword [edx]
    

    顺便说一句,你可以把这些行组合起来:

    mov edx, esi
    add edx, ebx
    

    进入:

    lea edx,[esi + ebx]
    

    【讨论】:

    • 确实,谢谢。另一件事,如果我可以的话:pastebin.com/dZ4UmJ0Q 你能在这里看到问题吗?它打印大量垃圾值和随机数,并在 printArray 中宣布分段错误
    • 在调用printf之前你只推送了一项!
    • @FRankKotler 是的。现在我已经解决了这个问题,但是在插入排序中的 loop_2 中会出现分段错误,请您帮我找出问题所在吗? pastebin.com/dbRh58f2
    • 如果您还有其他问题,您应该将它们作为单独的问题发布,而不是使用评论字段。请记住将相关代码和信息直接包含在您的问题中,而不是链接到它。
    猜你喜欢
    • 2021-03-02
    • 2016-11-12
    • 2022-01-23
    • 1970-01-01
    • 2017-12-21
    • 2014-03-16
    • 2018-02-21
    • 1970-01-01
    相关资源
    最近更新 更多