Re: [AVR-Chat] logical shift operation
2009-06-27 by Virgil Stana
maybe because 256 IS 0 (8 bit) ? --- On Fri, 6/26/09, Антощенков Роман Викторович <djantoxa@rambler.ru> wrote:
Show quoted textHide quoted text
From: Антощенков Роман Викторович <djantoxa@rambler.ru>
Subject: [AVR-Chat] logical shift operation
To: AVR-Chat@yahoogroups.com
Date: Friday, June 26, 2009, 8:10 PM
Hello!
I am coding in AVRStudio 4.16 and WinAVR-20090313
Code:
unsigned int i1 = 0;
unsigned int i2 = 0;
unsigned char c1 = 0;
i1 = 1024;
i2 = i1 >> 2;
c1 = (unsigned char)i1>>2;
Why c1 = 0? Must be c1 = 256!
Same in dissasemble view:
289: i1 = 1024;
+00000450: E080 LDI R24,0x00 Load immediate
+00000451: E094 LDI R25,0x04 Load immediate
+00000452: 839D STD Y+5,R25 Store indirect with displacement
+00000453: 838C STD Y+4,R24 Store indirect with displacement
290: i2 = i1 >> 2;
+00000454: 818C LDD R24,Y+4 Load indirect with displacement
+00000455: 819D LDD R25,Y+5 Load indirect with displacement
+00000456: 9596 LSR R25 Logical shift right
+00000457: 9587 ROR R24 Rotate right through carry
+00000458: 9596 LSR R25 Logical shift right
+00000459: 9587 ROR R24 Rotate right through carry
+0000045A: 839B STD Y+3,R25 Store indirect with displacement
+0000045B: 838A STD Y+2,R24 Store indirect with displacement
291: c1 = (unsigned char)i1>>2;
Why register R24? Must be R25
+0000045C: 818C LDD R24,Y+4 Load indirect with displacement
+0000045D: 9586 LSR R24 Logical shift right
+0000045E: 9586 LSR R24 Logical shift right
+0000045F: 8389 STD Y+1,R24 Store indirect with displacement
--
Best regards,
Roman Antoshchenkov
mailto:djantoxa@rambler. ru
[Non-text portions of this message have been removed]