First you need to decide on the calling convention , for example, take __fastcall , then if you have int 4 bytes, then ecx = order . Then [ecx] is the zero element of the array. You can start a loop with edi , for example, to list all the elements of an array through the [ecx + 4*edi] . If you have x64 mode, and not x86 , then there are other calling agreements, and the principle is slightly different. If I remember correctly (you can clarify here ), the first parameter is passed through rcx , then rdx , r8 and r9 . Passing through the array is the same - through [rcx + 4*rdi] , when rdi = 0, 1, 2 ...
Only one trouble - the name of the function, you do not know it. You can learn how to function with a linker error. When you start linking, an error will come out that the function is such and such with the name of какое-то-название certain какое-то-название defined, but not implemented. (For example, in one of my projects the name is so scary ?add@AddAsm@@YIIPAIPBIII@Z , although the original function was called AddAsm::add ). That is the name and you will need to enter in the assembly code. Below is pseudo-code (almost nasm), roughly similar to what you need (more specifically, I will not show it, because I don’t provide a higher level of specifics than the specifics of the question). By the way, the word extern not needed.
[BITS 32] global какое-то-название-функции ; Тут декларируется функция section .code какое-то-название-функции: ; Тут точка входа в функцию. push edi ; __fastcall обязан заботится о сохранении edi, esi и ebx xor edi, edi .loop: mov edx, [ecx + edi*4] ... Что-то делаем с edx ... lea edi, [edi + 1] ; ++ edi cmp edi, некое-число ; Сколько итераций нужно jne .loop pop edi mov eax, Бла-бла ; Это результат работы функции, передаётся через eax. ret 0 ; Выход без корректировки стека
Starting from this, try to solve your problem yourself.
orderis an array, then the size of the array must be passed to the function or an "final element" must be agreed. In another way, of course, it is possible, but this is all very compilable and very important. - KoVadimorderwill be a pointer (address) to the first (zero) element. Since pointers are most likely 4 bytes, then adding 4 to this address will get a pointer to the next element. - KoVadim++firstin assembler asaddq $4, %rdimight look like wherefirstisint*. - jfs