A89: Re: evaluating expressions
[Prev][Next][Index][Thread]
A89: Re: evaluating expressions
Hi!
> how can I evaluate an expression (a variable of the var-link)
> in an asm program? (and how to display the result?)
> ex: x contains 2
> y contains X^2+3
> how to get 7 for y?
It is explained in the documentation of TIGCCLIB release 1.5.
Basically (using C syntax):
push_parse_text("X^2+3");
NG_rationalESI(top_estack);
In ASM:
pea expr(pc)
jsr tios::push_parse_text
move.l tios::top_estack,-(sp)
jsr tios::NG_rationalESI
lea (sp,8),sp
...
expr: .ascii "X^2+3"
dc.b 0
Now, the result is on the top of the estack (read in TIGCCLIB
what is estack). You can retrieve the result by peeking estack
directly, or by using various TIOS functions. For example,
if you know in advance that the result is an unsigned short
integer, you can use estack_to_ushort. Using C syntax:
estack_to_ushort(top_estack,&var);
Using ASM:
pea var(pc)
move.l tios::top_estack,-(sp)
jsr tios::estack_to_ushort
lea (sp,8),sp
move.w var,d0
...
var:dc.w 0
After this, d0.w will contain the result.
Happy?
Zeljko Juric
Follow-Ups: