For either instance or example or illustration, if I do either:
lea ebx, eax
or
mov ebx, offset eax
or
mov ebx, addr eax
Then theoretically dword ptr[ebx] now refers to register eax, i.e. dword ptr[ebx] is now reference to register eax.
That means that if I do, for either instance or example:
invoke print, dword ptr[ebx]
This will print the contents/value/data of register eax and
mov dword ptr[ebx], ecx
This will set register eax to ecx, i.e. copy all bits of register ecx to eax, like doing eax = ecx in C.
This is like I did
mov eax, ecx
But neither:
lea ebx, eax
nor
mov ebx, offset eax
nor
mov ebx, addr eax
compiles and I get errors on all these three lines.
But I know that if I do:
invoke some_procedure, eax
then the assembler compiles this line, so it pushes register eax on the stack by copying all it's bits to the address that esp points at and then it does
sub esp,4
And then it does
call some_procedure
That is called: pass register eax by value, but I want to pass it by reference and not by value. If I do either:
invoke some_procedure, addr eax
or
invoke some_procedure, offset eax
or
invoke some_procedure, ref eax
Then I don't really expect that the assembler will really push either the offset or the address of register eax on the stack, because I believe him that this is impossible, but I want him to treat this as:
call some_procedure
Which is valid and inside some_procedure, everywhere the name of the first parameter is mentioned replace it by eax. replace it by ebx, if I do:
invoke some_procedure, ref ebx
Surely that this is possible to do this in compilation time, but I want to know if the masm assembler does support reference to register inside procedure or not by doing this trick? Does it know to do this trick in compilation time? If yes, then what is the syntax to invoke instruction and pass registers by reference then?
The effect to pass register by reference should be the same as passing any parameter by reference in C++ by typing the ampersand character after the type of the parameter in the definition of the function.
Same thing when I define local reference variables with the ampersand character, after I write down the type of the variable in C++ of course.
Note that ref reg32, i.e. all ref eax, ref ebx, ref ecx, ref edx and etc, I can write after invoke name_of_procedure, but only if the type of the parameter, where the ref reg32 was written, is dword. Otherwise error should be given.
Same for ref reg16, i.e. all ref ax, ref bx, ref cx, ref dx and etc, I can write after invoke name_of_procedure, but if the type of the parameter, where the ref reg16 was written, is word. Otherwise error should be given.
And so on.
Same thing if only either reg32 or reg16 was written without ref, parameter must be either dword (for reg32) or word (for reg16) of course. Otherwise error; operand size conflict.
What does the manual say?
Quote from: jj2007 on February 09, 2017, 01:08:54 AM
What does the manual say?
I don't understand your question. Please explain.
In my opinion, I think that reference to registers and passing them by reference when invoking any procedure can be very useful and efficient, because the compiler can translate the line, so there is no push and pop any parameter where register was passed by reference. Inside the procedure I access the parameter as I access the register, which is the fastest and best.