gnupic: Trouble with macros conditionally generating code
Subject:
Re: Trouble with macros conditionally generating code
From:
Pete Elmore ####@####.####
Date:
19 Nov 2004 09:42:44 +0000
Message-Id: <419DC042.2070803@petta-tech.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
| But, doesn't this version produce error 118 ("Error [118] Overwriting
| previous address contents.")?
| On the second pass, when the assembler overwrite the "nop"s, it should
| shout, if I am not wrong.
The nops never get overwritten. It generates either
bxf 0xa, 3
bxf 0xa, 4
call label
or
nop
nop
call label
Actually, that code was just to check if the problem was with the
assebler. I'm actually using something like
fcall macro label
if((high(label) & 8) == 8)
bsf 0xa, 3
else
bcf 0xa, 3
endif
if((high(label) & 0x10) == 0x10)
bsf 0xa, 4
else
bcf 0xa, 4
endif
call label
endm
It's harmless to set the bits if you don't need it, although it adds
unnecessary instructions.
| fcall MACRO dest
| LOCAL callsite = $
| LOCAL curpage = (callsite / 0x0800)
| LOCAL destpage = (dest / 0x0800)
| IF (curpage == destpage)
| call dest
| ELSE
| ERRORLEVEL -306
| pagesel dest
| call dest
| ERRORLEVEL +306
| ENDIF
| ENDM
I was going to do something like this, but the documentation for gpasm
says that pagesel changes pages with movlw and movwf, and I wanted to
avoid altering W (a few routines I wrote near the beginning of the
project (before I decided to take a more Forth-like approach) took W as
an argument, and I didn't want to re-write already debugged code unless
I finish before the deadline (ha ha ha! :P )) Also, "b[cs]f, b[cs]f,
call" is exactly the same number of instructions as "movlw, movwf,
call", so there's no code size or performance issue.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Debian - http://enigmail.mozdev.org
iD8DBQFBncBCv24lB609Ih8RAsnhAJ9h55an8QT0UOBv/H4tEKrKqvhFqwCfc06c
2BdjOEAubolk1qpOlTJ+LUg=
=gIJu
-----END PGP SIGNATURE-----