[Coco] CCASM procedures

Roger Taylor rtaylor at bayou.com
Thu Dec 9 03:28:44 EST 2004


Now, things are looking beautiful.  It's getting about time for a library 
to be built.  :)

Check out this small example.  All registers are preserved across procedure 
calls, nesting is supported, and you can have local and/or static variables 
within procedures if you like.

	org	3584

result	rmb	1

* pass-by-reference example

double	proc	param:byte,presult:word
dummy	var	1		reserve 1 local (stack) byte for no reason :)
static	rmb	1		reserve 1 static byte for no reason :)
	begin			procedure entry
	lda	param,u		access pass-by-value parameter
	lsla
	sta	[presult,u]	change pass-by-ref parameter
	clr	dummy,s		clear a local variable
	endproc

start	call	double,1,result		call main procedure
	lda	result
	sta	1024
	rts

	end	start




what code is generated?


                                          org 	3584	
                                           		
  0E00                  result            rmb 	1	
                                           		
                       * pass-by-reference example
                                           		
  0E01                  double            proc 	param:byte,presult:word	
               {$0000}  dummy             var 	1	reserve 1 local byte for 
no reason :)
  0E01                  static            rmb 	1	reserve 1 static byte for 
no reason :)
  0E02      34401F43                      begin 	procedure	entry
  0E06      32E9FFFF
  0E0A A6   44                            lda 	param,u	access pass-by-value 
parameter
  0E0C 48                                 lsla 		
  0E0D A7   D8 05                         sta 	[presult,u]	change 
pass-by-ref parameter
  0E10 6F   60                            clr 	dummy,s	clear a local variable
  0E12      1F343540                      endproc 		
  0E16      39
                                           		
  0E17      3436        start             call 	double,1,result	call main 
procedure
  0E19      CC
  0E1A      0E003406
  0E1E      86013402
  0E22      BD
  0E23      0E02
  0E25      32633536
  0E29 B6   0E00                          lda 	result	
  0E2C B7   0400                          sta 	1024	
  0E2F 39                                 rts 		
                                           		
               {$0E17}                    end 	start	

-- 
Roger Taylor




More information about the Coco mailing list