Author Topic: Making return values in procs  (Read 430 times)

Ascended

  • Member
  • ***
  • Posts: 331
Re: Making return values in procs
« Reply #15 on: April 26, 2018, 12:58:14 PM »
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.

AW

  • Member
  • *****
  • Posts: 1299
  • Let's Make ASM Great Again!
Re: Making return values in procs
« Reply #16 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.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Making return values in procs
« Reply #17 on: April 26, 2018, 03:33:02 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

  • Member
  • ****
  • Posts: 588
Re: Making return values in procs
« Reply #18 on: May 02, 2018, 08:59:23 AM »
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

  • Member
  • ****
  • Posts: 741
Re: Making return values in procs
« Reply #19 on: May 03, 2018, 07:41:44 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)
« Last Edit: May 03, 2018, 09:18:22 AM by RuiLoureiro »