This is a beginner question... but I am struggling on it for almost 2 full days now.
I have to implement a function in NASM cooperate with C,
which from main function (done in C) will pass a pointer array pointing to constant short arrays to the function, I have to sort the pointer according to the requirement which requires me to read the items in each constant short array. Since it's a pointer there will be no return from my function.
pointer passed to my function will be like this: const short *v[],
each *v[n] points to a different constant array, n size unknown, but terminates with null. Constant array size unknown as well, but terminates with a negative number (valid elements in the array guaranteed to be positive).
My question is, how do I access each individual element in those constant arrays?
I have successfully read the pointer array from the [EBP+8], and able to detect how many elements in the pointer array by shifting the address, but I could not figure out how do I access the constant array which pointer array is pointing to.
fragments of my code:
...
segment .text
global sort_vectors
sort_vectors:
enter 0,0
pusha
mov EBX, dword [EBP+8] ; const short *v[]
mov ECX, 0
.forloop:
;I am able to count how many elements in v from this for loop
mov EAX, dword [EBX+4*ECX]
cmp EAX, 0
jz .forloopj
...
;but I need to access each individual constant short array to do the sorting
...
inc ECX
jmp forloop
.forloopj:
...
Any hint on how to get to each constant short array? Thanks!
edit:
Ok, I have figured what I have done wrong.
Just realize const short is 2 bytes, I was using extended general register (4 bytes)
to read and write this whole time! Solved by only using lower part of the 32 bits register and it works now!
I may post the working codes later when the assignment is due.
Thanks to those who replied!
=================================================================