On Sat, 11 Sep 2010, pito wrote:

> push R0                       ; worst case - store everything
> push R1
> push R2
> .....
> push R31

Please be careful NOT to restore r28, r29
(register Y - your data stack pointer)
and r24, r25 - top of your stack.

>
> ld R10, Y+
> ld R11, Y+   ; takes c from stack
>
> ld R12, Y+
> ld R13, Y+   ; takes b from stack
>
> ld R14, Y+
> ld R15, Y+   ; takes a from stack

This is wrong - TOS is in r26:r25
(tosh:tosl) *NOT* in RAM!

> st -Y, R16
> st -Y, R17    ; puts m on stack
>
> st -Y, R18
> st -Y, R19    ; puts l on stack
>
> st -Y, R20
> st -Y, R21    ; puts k on stack

Same as above - just leave TOS in r26:r25
and don't restore it via pop:

> pop R31                       ; worst case housekeeping
> ....
> pop R2
> pop R1
> pop R0

Don't restore tosl, tosh, Y 
(r24, r25, r28, r29) - since then your
stack effects will be void (or just corrupted).

No need to save temp0..temp5 (r14, r15, r16,
r17, r18, r19, r20, r21).

r30 and r31 (zl, zh) are used as a scratchapad
register, so no need to save these too.

r2 and r3 should be zero, so no need to save that
on stack (use it or restore it to zero at exit).

(Matthias: I noticed that techdoc says R22:R23
are TOS and R24:R25 are W, in my case on ATmega328P
it's the other way around)

Please keep in mind that machine stack is not 
indefinite (64 bytes only). So if your routine
is pushing something on stack and doing some
calls it can get tight.

Regarding you other email, regarding "here", "dp"
etc. DP and HERE are stored in EEPROM (in my case EEPROM
address $6 and $8, respectively), please
see PFA_EFETCH how to read EEPROM from assembly
or push them on the data stack before running your
asm routing as parameters.

--Marcin

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Amforth-devel mailing list
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to