[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Time-efficient read of high byte in two-byte variable
From: |
Ralph Mason |
Subject: |
RE: [avr-gcc-list] Time-efficient read of high byte in two-byte variable |
Date: |
Fri, 9 May 2003 10:07:11 +1200 |
I found that
INLINE u_short lpw(u_short* addr)
{
union
{
u_short val;
struct
{
u_char low;
u_char high;
};
} ret;
ret.low = (u_char) PRG_RDB(addr);
((u_char*)addr)++;
ret.high = (u_char)PRG_RDB(addr);
return ret.val;
}
Generated ideal assembly code. Perhaps you can use the same idea (cast it
to a strut and access the byte you want.
Let me know how it works out.
Ralph
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of Wallace White
> Sent: Friday, 9 May 2003 9:45
> To: address@hidden
> Subject: [avr-gcc-list] Time-efficient read of high byte in two-byte
> variable
>
>
> 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
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.461 / Virus Database: 260 - Release Date: 10/03/2003
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.461 / Virus Database: 260 - Release Date: 10/03/2003
RE: [avr-gcc-list] Time-efficient read of high byte in two-byte variable,
Ralph Mason <=