Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MOV into a register specified by macro argument

I'm trying to execute a mov operation in a macro in AVR assembly. I want to specify the target by a numeric argument to a macro. I am using the Atmel Studio assembler.

I'm trying to do something like this:

; accepts 1 argument: target register.
.macro move_r10_into
  mov @0, r10 
.endmacro

; usage example:
move_r10_into 1 ; So this should do mov r1, r10

But when doing it like this, I get the error "Invalid register". Using r@0 instead gives the error "Unexpected (". Trying (r@0) results in "unexpected REGISTER".

How do I do this?

like image 520
Thom Wiggers Avatar asked Dec 18 '25 01:12

Thom Wiggers


1 Answers

I didn't notice this had been mentioned as a workaround in a comment by jester as I was typing, but passing in the full register name does work. I just added a few lines so it could easily be tested in the simulator:

.macro move_r10_into
    mov @0, r10 
.endmacro

inc r10
move_r10_into r1
nop

However you've mentioned in a comment wanting to be able to call it from a loop. Check the datasheet for your specific device but typically the registers R0-31 are mapped into data addresses 0x00 - 0x1F. That means you can access them using indirect data access by making use of the pointer registers as in the following example:

.macro move_r10_into
    ldi zl, @0 ; Load data address into Z pointer
    ldi zh, 0  ; This will result in R30/31 being changed
    st z, r10
.endmacro

inc r10
move_r10_into 1 ; So this should do mov r1, r10
nop
like image 92
PeterJ Avatar answered Dec 20 '25 18:12

PeterJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!