Nice concept, but wat you want is not that easy with MPASM.
MPASM makes one pass (pass one) to determine the locations of all labels,
and a final one (pass two) to generate the code. In pass two it checks
whether all labels still have the same value. If that is not the case, it
bails out (it should, because it could have created wrong code).
I can think of some solutions, but those are much more complex than what
you did.
You could try:
- use a macro declare_label to declare the labels, and keep your own label
administration
- reform all procedures into macros, and expand them in inverse-call order
in the second pass only
- try to find a solution which always expands to the same number of
instructions
By the way, you could replace your callpage macro obfusciated call macro.
If I remember well the principle is:
_call macro x
endm
#define call _call
Within the macro _call you'll have to undefine call before you can use the
normal call,
and after that you must define it again.
I have used these kind of constructs to make if then else and looping
macro's,
but I finally gave up because assembling took too long. I might try it
again some
time with my new PC.
----------
> From: Morgan Olsson <.....mrtKILLspam
.....INAME.COM>
> To: EraseMEPICLISTspam_OUT
TakeThisOuTMITVMA.MIT.EDU
> Subject: Automatic call optimization macro
> Date: Thursday, February 05, 1998 01:25
>
> I have mentioned it before, and now I«ve tried it:
>
> ; Following macro I want to use instead of call instructions when I«m not
> sure
> ; if the routine I call (target) is in the same page as the calling
routine.
> ; Writing include files I don«t want to decide either, as they should be
> universal.
> ; The macro senses if there is need to set PCLATH.
> ; If setting PCLATH (corrupt W) it saves and restores W in Wtemp if
Wtemp<>0.
> ; So we have fully automatic code optimization!
> CALLPAGE macro target,Wtemp
> if high target == high $ ;No need to change PCLATH
> messg "CALLPAGE evaluated to simple call"
> else
> if Wtemp == 0 ;Do not save and reload W, +2 instructions
> movlw high target
> movwf PCLATH
> else ;Save and restore W using register adress Wtemp, +4
instr.
{Quote hidden}> movwf Wtemp
> movlw high target
> movwf PCLATH
> movf Wtemp,W
> endif
> endif
> call target
> endm
>
> ;Of course, we could also make a GOPAGE macro the same way.
>
> I think it would work really great if it was not for the compiler:
> I get an almost endless list of errors like
> "
> Error[116] C:\MO\PROG\PIC\P\BAL01\MONIT.ASM 147 : Address label
> duplicated or different in second pass (monitio)
> Error[116] C:\MO\PROG\PIC\P\BAL01\MONIT.ASM 150 : Address label
> duplicated or different in second pass (monitiorot)
> Error[116] C:\MO\PROG\PIC\P\BAL01\MONIT.ASM 160 : Address label
> duplicated or different in second pass (monitiorotutH)
> Error[116] C:\MO\PROG\PIC\P\BAL01\MONIT.ASM 162 : Address label
> duplicated or different in second pass (monitiorotutOK)
> "
> etc, etc...
> Well, the macro seem to work, as the adresses change.
> Nice, that is the goal, right.
>
> So, I just want the compiler to run more passes, and we are there!
> But how to make it run more passes ??
> Are there other obstacles?
>
> Thank you in advance.
> /Morgan
>
> PS Strange... the nice song "Write in C" keep running in my mind more
and
> more... But I do«t have time to learn C now; deadline monday... probably
> meaning I«m dead tuesday... DS
> / Morgan Olsson, MORGANS REGLERTEKNIK, SE-277 35 KIVIK, Sweden \
> \ mrt
spam_OUTiname.com, ph: +46 (0)414 70741; fax +46 (0)414 70331 /