BBC BASIC for Windows
« Returning values from ASM functions »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:24pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Returning values from ASM functions  (Read 956 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Returning values from ASM functions
« Thread started on: Jul 17th, 2010, 7:56pm »

I'm a bit embarrassed to have to ask, but...

I quite often - nearly always, in fact - push all registers onto the stack at the beginning of a routine:

Code:
.routine
pushad ; preserve registers

(do stuff)

popad ; restore registers
ret 


But I find that when I need to return a value in EAX, I do this:

Code:
.routine
pushad
(do some stuff...)
(put some value in EAX)
mov [^temp], eax
popad
mov eax, [^temp]
ret
 



Is there a neater way to return a value in EAX without stashing the return value in a temporary memory location first?


Thanks.


David.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Returning values from ASM functions
« Reply #1 on: Jul 17th, 2010, 9:53pm »

on Jul 17th, 2010, 7:56pm, David Williams wrote:
Is there a neater way to return a value in EAX without stashing the return value in a temporary memory location first?

I don't know whether you would consider it 'neater', but this is the code I invariably use:

Code:
      mov [esp+28],eax
      popad
      ret 

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Returning values from ASM functions
« Reply #2 on: Jul 18th, 2010, 7:36pm »

on Jul 17th, 2010, 9:53pm, Richard Russell wrote:
I don't know whether you would consider it 'neater', but this is the code I invariably use:

Code:
      mov [esp+28],eax
      popad
      ret 

Richard.


Thank you!


David.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls