News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Making return values in procs

Started by Lonewolff, April 26, 2018, 09:56:09 AM

Previous topic - Next topic

Lonewolff

Yeah, I thought of something like this, but it would slowdown the code considerably.

And I have made my functions 'data.' free. So there isn't any hidden memory usage, also using registers as much as I can to keep speed right up there.

aw27

There is no difference between C/C++ and MASM, simply C/C++ hides the complexity from you.

"...  and larger structures and class objects .... are returned in memory. To pass "in memory", the caller allocates memory and passes a pointer to it as a hidden first parameter; the callee populates the memory and returns the pointer, popping the hidden pointer when returning."

There is really no other way to do it without a lot of malabarism.

Lonewolff

Quote from: aw27 on April 26, 2018, 03:17:27 PM
There is no difference between C/C++ and MASM, simply C/C++ hides the complexity from you.

"...  and larger structures and class objects .... are returned in memory. To pass "in memory", the caller allocates memory and passes a pointer to it as a hidden first parameter; the callee populates the memory and returns the pointer, popping the hidden pointer when returning."

There is really no other way to do it without a lot of malabarism.

Ah cool. That makes a lot of sense.

LordAdef

Not for the faint of hearts, as Hutch says

welcome to the world of macho programmers, if it's only one line of code, it's not asm (surely, this is only a joke :D)

RuiLoureiro

#19
Quote from: Ascended on April 26, 2018, 11:55:41 AM
A)   Ok, but just say you have the space created for blahC in the .data section?
B)   No way to write the result directly to that without passing as a parameter?
Your question B) seems to me curious because you dont want to pass the output address as
a parameter. And the answer to your question is YES you can ... but you have a lot of problems ...
Quote
.data?
blahC   dd 16 dup (?)     ; for matrix 4x4 real4
.code
MultiplyMatAbyB      proc   pMatA:DWORD, pMatB:DWORD
                              push   edi
                              mov   edi, offset blahC
                              ; now we have HERE the output address in edi
                              ; or replace edi by edx and comment  push and pop

                              ; do what you want


                              pop   edi
                              ret
MultiplyMatAbyB      endp
So, for each output matrix blahD, blahE,...,blahZ you need to write one procedure to do what you want to do. Is this what you want to do ? Is it usable ? (maybe if you dont need to save each result)