[Coco] CCASM procedures
Roger Taylor
rtaylor at bayou.com
Thu Dec 9 23:54:11 EST 2004
At 05:59 AM 12/9/2004, you wrote:
>Instead of passing the parameters in one or both of the stack registers,
>you might consider that this should all be done by CCASM. In other words,
>when CCASM reads a section of code defined as a "proc", it should store in
>its own memory the variables and apply them within the procedure as the
>source code calls procs. The assembled program won't know or see this and
>all registers in a proc will behave in a normal fashion.
Macros work completely different because, as you know, the code is
duplicated anytime you use the macro. Btw, macros *are* on my agenda for
CCASM very soon.
Procedures/subprograms are based on isolation. A procedure or subprogram
should not know anything (give or take) about the outside world or calling
program, and there should be only one instance of a procedure. You pass
parameters into the procedure, it does its job, and you can optionally get
something back (from a function).
The reason the procedures need to work the way they do is to also allow a
library to be compiled into object code for linking in. Stuff like this
will come soon, but I have to start somewhere, so I think a source-code
based library is great for now.
As of tonight, I have decided to use ,U as the means for accessing
procedure parameters and local variables. The S stack is unpredictable,
especially since you can preserve your own registers across procedure calls
by PSHS/PULS. Add in the fact that you can call other procedures from
within a procedure, and you just can't predict where the stack will be, so
how can you use the precomputed offsets for parameters and local
variables? The only way is the copy S to U at a certain point, then use U.
Btw, U is also pushed to the S stack and preserved automatically, as well
as D. You must preserve any other registers you use, yourself.
Here's the latest working example....
I'm still studying whether the local variable offsets are correct since I'm
dealing with negative offsets on the stack.
CCASM 2.93: assembling cross6809.asm to pro.bin
org 3584
0E00 result rmb 1
* pass-by-reference example
0E01 square proc param:byte,presult:word
{$FFFE} aa var 2 reserve 1 local
byte for no reason :)
{$FFFC} bb var 2
0E01 34401F43 begin square procedure entry
0E05 32E9FFFC
0E09 A6 44 lda param,u access
pass-by-value parameter
0E0B 48 lsla
0E0C A7 D8 05 sta [presult,u] change
pass-by-ref parameter
0E0F ED 5E std aa,u access local variables
0E11 ED 5C std bb,u
0E13 1F343540 endproc
0E17 39
0E18 3406 start call square,2,result call main
procedure
0E1A CC
0E1B 0E003406
0E1F 86023402
0E23 BD
0E24 0E01
0E26 3506
0E28 3263
0E2A B6 0E00 lda result
0E2D B7 0400 sta 1024
0E30 39 rts
{$0E18} end start
--
Roger Taylor
More information about the Coco
mailing list