Search code examples
assemblyavr

How to modify .byte variable in AVR


In this program, I need to have a variable called globalSum (globalSum: .byte 0 for init). I am having trouble figuring out how to add values from r24 to this variable. Should I just use the Z register or is there a method to add to such a variable?


Solution

  • When you write :

    globalSum: .byte 0
    

    What actually happens is that you just allocated 0 bytes in program memory, and set a label (globalSum) for these 0 bytes...

    If you want a variable, it goes something like this ( in native AVR assembly):

    .DEF globalSum = r16
    

    Now you can do stuff with a kind of variable called globalSum, for example set it to 0:

    LDI globalSum, 0