avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Time-efficient read of high byte in two-byte variable


From: Wallace White
Subject: [avr-gcc-list] Time-efficient read of high byte in two-byte variable
Date: Thu, 08 May 2003 14:44:39 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3.1) Gecko/20030425

What's a good, quick way to read the high byte of a two-byte variable in C?

I am sending an int out the UART, unformatted. Here's what my tries so far have compiled into (my 16-bit variable is encPosDetentsNow):

872:    UDR = (unsigned char) (encPosDetentsNow >> 8);
+00000517: 91600079 LDS R22,0x0079 Load direct from data space +00000519: 9170007A LDS R23,0x007A Load direct from data space
+0000051B:   2F87        MOV     R24,R23          Copy register
+0000051C:   2799        CLR     R25              Exclusive OR
+0000051D: FD87 SBRC R24,7 Skip if bit in register cleared
+0000051E:   959A        DEC     R25              Decrement
+0000051F:   B98C        OUT     0x0C,R24         Out to I/O location

The following is a little shorter:

871:   UDR = (((unsigned int) encPosDetentsNow) & 0xFF00) >> 8;
+00000517: 91600079 LDS R22,0x0079 Load direct from data space +00000519: 9170007A LDS R23,0x007A Load direct from data space
+0000051B:   2F87        MOV     R24,R23          Copy register
+0000051C:   2799        CLR     R25              Exclusive OR
+0000051D:   B98C        OUT     0x0C,R24         Out to I/O location

What I'd really like to get would be just
        LDS     R23,0x007A      ; load the high byte
        OUT     0x0C,R24        ; and output it to UDR
without going to inline assembly.

This is using the current WinAVR with -O3.

Thanks,
Wallace



reply via email to

[Prev in Thread] Current Thread [Next in Thread]