Jac*_*ack 2 linux assembly nasm
我有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
Run Code Online (Sandbox Code Playgroud)
现在......当我尝试用nasm编译我的代码时,我在注释中包含星号的行上出现"未指定操作大小"的错误:P这是基本的插入排序,我不确定会出现什么问题.请赐教.
数据[edx]可以是任何内容,因此汇编程序不知道它的大小.您必须指定要推送/弹出的数据的大小.例如,如果你想推/弹dword(32位)你会写:
push dword [edx]
pop dword [edx]
Run Code Online (Sandbox Code Playgroud)
顺便说一下,你可以结合这些线:
mov edx, esi
add edx, ebx
Run Code Online (Sandbox Code Playgroud)
成:
lea edx,[esi + ebx]
Run Code Online (Sandbox Code Playgroud)