我遇到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编译我的代码时,我在注释中包含星号的行上出现“未指定操作大小”的错误:P 这是基本的插入排序,我不确定会出现什么问题。 请赐教。
答案 0 :(得分:8)
[edx]
处的数据可能是任何数据,因此汇编程序的大小是未知的。您必须指定要推送/弹出的数据的大小。例如,如果你想推/弹dword
(32位),你可以写:
push dword [edx]
pop dword [edx]
顺便说一下,你可以将这些行组合起来:
mov edx, esi
add edx, ebx
成:
lea edx,[esi + ebx]