gnupic: [gnupic] Extensions to gpasm


Previous by date: 6 Jun 2005 17:38:42 +0100 Extensions to gpasm, Peter Onion
Next by date: 6 Jun 2005 17:38:42 +0100 Re: [gnupic] help - DIY PCB manufacture, Ian Jackson
Previous in thread:
Next in thread:

Subject: [gnupic] Extensions to gpasm
From: Bill Freeman ####@####.####
Date: 6 Jun 2005 17:38:42 +0100
Message-Id: <17060.31822.89747.100569@localhost.localdomain>

	The way that I'd like to be able to do this is with a macro.
Something like:

	movlw	bits C2OUT, C1OUT, CM2

	Sadly, IIUC, MPASM/gpasm macros aren't up to the task in two
areas: 1. The macro name must appear in the opcode position; and
2. there isn't a good way to deal with variable numbers of parameters.

	What you can do is:

bits3	macro	op, a1, a2, a3
	op	1<<(a1) | 1<<(a2) | 1<<(a3)
	endm

Which you can use like this:

	bits	movlw, C2OUT, C1OUT, CM2

(The parentheses allow you to safely use expressions as parameters.
"<<" has higher expression priority than "|", so the parentheses
that you used in your example are unnecessary.)

	Unfortunately you also need bits1, bits2, bits4, bits5, bits6
and bits7 (and bits8 if you don't want to just recognize that it will
be 0xFF), and you need to select which you use based on how many bit
parameters you get.

	Your bit operator has some charm, but it has the same number
of characters (since your parentheses are unnecessary, at least in
this context) as the "1<<" operator, and it's just another operator
to remember for this particular case.

	I would much rather see an extension to the macro facility
that would allow variable numbers of parameters (probably including
some looping construct that looped over the set or arguments supplied,
or a pseudo parameter that tells how many parameters were received, to
be used with while, and a means of indexing into the parameter list).
Such macro enhancements would be fun in a variety of circumstances.

							Bill


Peter Onion writes:
 > Over on the piclist I've been asking how people deal with the situation
 > where you want to set a number of bits in a peripheral configuration
 > register....
 > 
 > General replies are like this...
 > 
 >   movlw (1<<C2OUT)|(1<<C1OUT)|(1<<CM2)
 > 
 > which I think it UGLY and easily misread!
 > 
 > I looked at the gpasm code for implementing things like "high" and "low"
 > and quickly added "bit" which converts a bit number into its byte value,
 > so that the above code can be written as 
 > 
 > 	movlw 	bit C2OUT + bit C1OUT + bit CM2
 > 
 > which I think is much better.
 > 
 > Now I know this will break compatibility with MPASM, but does anyone
 > else think this is a useful idea ?
 > 
 > Peter 
 > 
 > 
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: ####@####.####
 > For additional commands, e-mail: ####@####.####

Previous by date: 6 Jun 2005 17:38:42 +0100 Extensions to gpasm, Peter Onion
Next by date: 6 Jun 2005 17:38:42 +0100 Re: [gnupic] help - DIY PCB manufacture, Ian Jackson
Previous in thread:
Next in thread:


Powered by ezmlm-browse 0.20.