A89: Re: returning values


[Prev][Next][Index][Thread]

A89: Re: returning values




> Does anyone know how to return a value from a asm program 
> written in C?  For example, let's say that for some bizarre
> reason, I wanted to make a C asm prog that acted as a function
> (ie accepts arguments) and returns a value...
> 
> hmmmm. like let's say the program "square" accepts a value, 
> and returns the square.
> 
> :square(5)
> and it returns 25
> 
> How do I do this? (and what if I want to return values of a
> different type,  like lists, matrices, strings, etc?)

If you use tigcclib releases prior to 1.5, this is not simple. But,
in release 1.5 a directive is introduced for this. This is explained
well in the manual, read section "How to make a program which returns
a value to TI-Basic". Briefly, include

#define RETURN_VALUE

at the beginning of the program, then push a wanted value (or list,
string, etc.) to the expressions stack using some of functions from
estack.h header file (again, you need tigcclib 1.5, it can be picked
from ticalc). Note that tigcclib included with last release of TIGCC
is 1.1 although readme says that it is 1.5!

There is still one problem. AMS 2.xx does not allow ASM programs in
expressions, so returning value is of limited use. E.g, square(5)
will work, but square(5)+1 or square(5)->a will not! Fortunately, the
last release of DoorsOS fixes this (the next release of UniOS will 
fix this too).

Zeljko Juric