[Coco] CCASM procedures

Roger Taylor rtaylor at bayou.com
Sat Dec 4 23:56:08 EST 2004


So far, here is where I'm at.  I need some feedback on whether my methods 
are "good" or not.

I haven't added the actual CALL function yet which will push the supplied 
parameters to the stack then call the procedure, etc.  I'm also not 
planning on doing too much or any type checking or checking too much to see 
if the CALL parameters are legal or not.

The first listing is the source code defining 2 procedures, and the second 
listing is what CCASM output during assembly.


	org	3584

* Convert to upper: toupper(char c)
toupper	proc	chr:byte
	lda	chr,s		Get char argument
	cmpa	#'a'		Lower case?
	blo	?1		No, leave alone
	cmpa	#'z'		Lower case
	bhi	?1		No, leave alone
	anda	#%11011111	Convert to upper
?1	rts
	endproc

* Convert to lower: tolower(char c)
tolower	proc	chr:byte
	lda	chr,s
	cmpa	#'A'		Upper case?
	blo	?1		No, leave alone
	cmpa	#'Z'		Upper case
	bhi	?1		No, leave alone
	ora	#%00100000	Convert to lower
?1	rts
	endproc

	end


LISTING-->

                                         org 	3584	
                                           		
                       * Convert to upper: toupper(char c)
                        toupper           proc 	chr:byte	
  0E00 A6   62                            lda 	chr,s	Get char argument
  0E02 81   61                            cmpa 	#'a'	Lower case?
  0E04 25   06                            blo 	?1	No, leave alone
  0E06 81   7A                            cmpa 	#'z'	Lower case
  0E08 22   02                            bhi 	?1	No, leave alone
  0E0A 84   DF                            anda 	#%11011111	Convert to upper
  0E0C 39               ?1                rts 		
                                          endproc 		
                                           		
                       * Convert to lower: tolower(char c)
                        tolower           proc 	chr:byte	
  0E0D A6   62                            lda 	chr,s	
  0E0F 81   41                            cmpa 	#'A'	Upper case?
  0E11 25   06                            blo 	?1	No, leave alone
  0E13 81   5A                            cmpa 	#'Z'	Upper case
  0E15 22   02                            bhi 	?1	No, leave alone
  0E17 8A   20                            ora 	#%00100000	Convert to lower
  0E19 39               ?1                rts 		
                                          endproc 		
                                           		
               {$0000}                    end 		

?10007                   =[     0E19]		?10006                   =[     0E0C]
toupper_chr              =[0001_0002]		tolower_chr              =[0001_0002]


Note that the tolower_ and toupper_ local symbols in the bottom table 
contain two joined 16-bit codes.
The MSW (on the left) is how many bytes that parameter needs.  The LSW is 
the offset into the stack, since it's a local variable.
These codes are used in the expression evaluator whenever you're inside of 
a procedure, to translate the symbol into its "address" (the offset in this 
case) so that it works seamlessly with the indexed instructions, such as 
variablename,s.

Before I go too far with all of this, I wanted to get some opinions so that 
I won't end up having to change too much stuff later and possibly breaking 
a bunch of source code somebody spent their hard hours on.

-- 
Roger Taylor




More information about the Coco mailing list