Re: Align Data and RAM Gaps

Erik Christiansen <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <20140809083926.GB2743@ratatosk>
On 09.08.14 18:18, Erik Christiansen wrote:
> 
>    ldiw  Z,buf

What, that's not an avr mnemonic? It is if you have this in a header
file:

; Data Pointer (or any word value) initialisation of a register pair.
; Usage: ldiw  Y,some_data
;        ld    r16,Y          ; OR lpm r16,Y if some_data is in flash.
                              ; Avoids need for manual endianness perfection.
   .macro ldiw reg,addr
   ldi   \reg,lo8(\addr)
   ldi   (\reg + 1),hi8(\addr)
   .endm

And for completeness:

; Program Pointer (word address) initialisation of a register pair.
; Usage: pptr  Z,program_address
;        icall

   .macro pptr reg, addr
   ldi   \reg, pm_lo8(\addr)           ; Word addressed program memory.
   ldi   (\reg + 1), pm_hi8(\addr)
   .endm

There's no reason why we should do word operations by hand, especially
with that lo8/pm_lo8 guff to increase the likelihood of human error.

Erik

-- 
Programs must be written for people to read, and only incidentally for
machines to execute.                            - Abelson and Sussman
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.