• AVR Freaks

Helpful ReplyHot!asm macros - operating on file register address

Author
Foil
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2006/08/13 10:35:02
  • Location: 0
  • Status: offline
2020/04/08 12:22:45 (permalink)
0

asm macros - operating on file register address

Consider part of this macro as an example:
 
addff.bs MACRO ARG1,ARG2,ARG3
 
IF ARG1 >= conACS_MEM_STOP
banksel ARG1
ENDIF
 
...
 
The IF arguments fails during build if ARG1 is a file register name that has been defined using res directive
with the message "Operand contains unresolvable labels or is too complex".
 
Obviously here my intention is not to operate on the file register content itself, but its address that it has been
given during build, to find out if the register is an access register or not, but it seems it is not possible,
at least not the way I am trying to do it.
 
For very simple macros operating one file register only, I usually make different versions of it, with .ac or .bs 
versions for operationg on an access file register, or where a bankselect is needed in macro, to increase readability.
 
Some simple macros operates on 2 file registers, and for the .bs version it would be nice to establish
if one of the file registers spesified as arguments might be an access register, to save a bankselect, or
comparing the upper part of the 2 file registers to check if they are in the same bank, also to save a bankselect.
 
My question is, is there another way to do this, other than adding even more arguments to the macro to specify
file register type?
 
Thanks in advance for any replies.
#1
Beau Schwabe
Starting Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2019/09/23 21:16:53
  • Location: 0
  • Status: offline
Re: asm macros - operating on file register address 2020/04/08 15:38:51 (permalink)
0
I'm an Assembly guy, so you might need to make a few adjustments, but this will move the Adress of ARG1 into the contents of ARG2...
 

ARG1    res 1
ARG2    res 1
ARG3    res 1    

RESVECT        CODE        0x0000
    
        
MacroTest                MACRO    ARG1, ARG2, ARG3
                    movlw    ARG1            ; <-- Get Arg1 Address
                    movwf    ARG2            ; <- Move Arg1 Address to Arg2's content
                    ENDM        
                
MAINLP:        
        MacroTest   ARG1, ARG2, ARG3    


        goto    MAINLP

#2
1and0
Access is Denied
  • Total Posts : 10779
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: asm macros - operating on file register address 2020/04/08 15:45:06 (permalink) ☄ Helpfulby Foil 2020/04/09 00:45:27
+1 (1)
The assembler does not know the addresses of relocatable operands until the linker allocates them; hence the unresolvable error.
 
That being said, you'll have to learn to allocate your variables that operate with each other in groups to minimize banking.
#3
1and0
Access is Denied
  • Total Posts : 10779
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: asm macros - operating on file register address 2020/04/08 15:47:19 (permalink)
0
Beau Schwabe
I'm an Assembly guy, so you might need to make a few adjustments, but this will move the Adress of ARG1 into the contents of ARG2...

That is not what OP is asking about. OP wants a "smart" macro that can reduce banking instruction.
#4
Foil
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2006/08/13 10:35:02
  • Location: 0
  • Status: offline
Re: asm macros - operating on file register address 2020/04/09 01:10:30 (permalink)
0
1and0
The assembler does not know the addresses of relocatable operands until the linker allocates them; hence the unresolvable error.
 
That being said, you'll have to learn to allocate your variables that operate with each other in groups to minimize banking.




I suspected there was a good reason this did not work, thanks for the clarification.
 
 
#5
crosland
Super Member
  • Total Posts : 1936
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: asm macros - operating on file register address 2020/04/09 04:04:46 (permalink)
0
1and0The assembler does not know the addresses of relocatable operands until the linker allocates them; hence the unresolvable error.
 



I was stung by this a few years ago in MPASM trying to port someone else's absolute mode code, that assembled just fine, to using relocatable object modules and the linker.
#6
1and0
Access is Denied
  • Total Posts : 10779
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: asm macros - operating on file register address 2020/04/09 05:27:07 (permalink)
0
crosland
 
I was stung by this a few years ago in MPASM trying to port someone else's absolute mode code, that assembled just fine, to using relocatable object modules and the linker.

In absolute mode, where the linker is not used, this will work because all addresses are known at assembly time. In this respect, absolute mode is better than relocatable mode as complex operations on identifiers are possible.
 
#7
Foil
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2006/08/13 10:35:02
  • Location: 0
  • Status: offline
Re: asm macros - operating on file register address 2020/04/10 03:27:12 (permalink)
0
It should be possible to create a script that plucks the file register addresses out of the map file
generated by the linker, and then use the address and file register name information to create a map file
consisting of file register statements, like absolute mode, where every file register name has a fixed numerical postfix.
 
This file can be included in top of main code file, and in the macros one would have to use ARG1#v(i) statements
to apply the postfix to the relocatable file register names.
 
The script would have to be run before build, and rely on content of map file from previous build.
 
This scheme would have its share of problems of course, during initial build the script would have no map file at all,
and it would fail as the macros would use non existing identifiers.
 
 
During the next build, the missing register names could be fetched from the error file from the previous build, and
a  map file could be generated with only those, set du dummy values, and the build would pass. 
 
It would have to be run a third time during an additional build, with script now using entries from now existing map file.
 
And of course a script should run after build to check of the file register entries in linker map file has changed 
since last build, and if so, prompt the user to an additional build. 
 
Also, for this to work, the mapping of file registers needs to be consistent, and not change at random
from build to build, unless there are changes in file register setup of course. Not sure if this is the case or not.
 
This is just a rough idea, I know there are other issues as well that would need to be addressed.
 
#8
Jump to:
© 2020 APG vNext Commercial Version 4.5