increment addressing mode in macro

Discussion in 'Embedded Systems and Microcontrollers' started by snr, Mar 28, 2016.

  1. snr

    Thread Starter New Member

    Mar 14, 2016
    6
    0
    I try to write my own clear which clears a number of locations starting with an address by using a macro. i.e. clear $1200 5 it clears content of from $1200 to $1205. However, I can't do like in macro
    Code (ASM):
    1.  
    2. ;The code section works well, The issue I can't integrate it in macro
    3. LDX $1200
    4. CLR 1, X+
    5.  
    In macro try
    Code (ASM):
    1.  
    2. clear MACRO
    3.       LDX \1
    4.       LDAB #\2
    5. \@SONERLOOP
    6.       CLR 1, x+ ; it will clear current address then increment adress  one more not content (first issue incrementing adress)
    7.       DECB #\2 ; I have also tried DEC to decrement counter but not work (second issue decrementing counter)
    8.       BNE \@SONERLOOP
    9.       ENDM
    10.  
    How can it be fixed?
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    It would help immensely if you could identify the assembler that you are using to construct this macro. Unfortunately each assembler does these things just a bit differently. It is not a case of learning one assembler and knowing them all. Here you have to learn each one in excruciating detail.
     
    absf likes this.
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    What errors does it report? I don't know the syntax for your assembler but in lines 3 and 4 of the macro, it looks like you are using parameters. In every assembler I know of, you have to specify those in the macro definition i.e.
    Clear MACRO (target,count)
    LDX \target
    LDAB #\count
    ENDM
    The macro expansion is a simple text substitution so invoking
    Clear ($1200,5)
    expands to
    LDX $1200
    LDAB #5

    Do you have the assembler reference to clear up the syntax for the 68HC12? Post a link to it if so.
     
    absf likes this.
  4. snr

    Thread Starter New Member

    Mar 14, 2016
    6
    0
    thanks for the advise. that is hcs12
     
  5. snr

    Thread Starter New Member

    Mar 14, 2016
    6
    0
    I can't use increment addressing with argument CLR 1, \1+ erroring register expected but argument is already register. HCS12 instruction reference manual pdf link: http://www.nxp.com/files/microcontrollers/doc/ref_manual/CPU12RM.pdf
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    My hcs12 assembler does not have macros like that. Who is the vendor of your particular assembler?

    What you are trying to do is called "token pasting". What you want to do is concatenate the expansion of the argument \1, which should be a register name and the + operator. The assembler might need a delimiter between the \1 and the + or maybe some brackets around the \1. Some manual digging might help.
     
  7. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    761
    The micro in question, does it have indirect addressing mode?

    Clearing RAM memory, which I do upfront at startup, is certainly simple in the PIC 18F family.
     
  8. snr

    Thread Starter New Member

    Mar 14, 2016
    6
    0
    no there are only inherent, immediate, direct extended, relative modes.
     
  9. snr

    Thread Starter New Member

    Mar 14, 2016
    6
    0
    I'm using codewarrior and I have read the macro usage in Mazidi's HCS12 book. I try to make my own clear. Like

    Clear: “clear <address> <numberOfLocations>”

    Clears a number of locations starting with an address. For instance: clear $1200 12

    Then writes zero to 12 locations between $1200 and $120B.

    Also, I wonder that there is another way to use macro. Can I write it in other way?
     
  10. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    Not familiar with Code Warrior so I can't with the specific problem. I do understand what you're trying to do, but I'll need to research the specifics of the Macro Processor.
     
Loading...