gnupic: handy 18f goto/call macros
Subject:
handy 18f goto/call macros
From:
David McNab ####@####.####
Date:
11 Feb 2005 05:21:28 +0000
Message-Id: <420C40D1.1000000@rebirthing.co.nz>
Hi,
Further to the issue of bra/rcall instructions out of range, and Craig's
recent fix to gpasm/gplink in regard to warnings:
I've written two macros, called 'mcall' and 'mgoto', which compute the
distance between origin and destination, and generate the shortest
possible instruction.
'mgoto somelabel' generates a 'bra somelabel' if 'somelabel' is within
[-1024,1023] bytes from the origin, otherwise it generates
'goto somelabel'.
Similarly, 'mcall somelabel' generates a 'rcall somelabel' if
'somelabel' is within relative call range of origin, otherwise it
generates 'call somelabel'.
These macros only work if the origin and destination are within the same
.asm file, but are a convenience which take away from the tedium of
worrying about whether jumps/calls are in range, and monitoring gpasm
warnings.
Macros source follows:
--
Cheers
David
-----------------------------------
; use 'mcall' in place of 'rcall' and 'call', wherever the
; destination resides in the same source file
mcall macro target
local distance
distance set (target - $)
if ((distance >= 0) && (distance <= 1023)) || ((distance < 0) &&
(distance >= -1023))
messg "mcall: generating rcall"
rcall target
else
messg "mcall: generating call"
call target
endif
endm
; use 'mgoto' in place of 'bra' and 'goto', wherever the
; destination resides in the same source file
mgoto macro target
local distance
distance set (target - $)
if ((distance >= 0) && (distance <= 1023)) || ((distance < 0) &&
(distance >= -1023))
messg "mgoto: generating bra"
bra target
else
messg "mgoto: generating call"
goto target
endif
endm