EmbeddedRelated.com
Forums

How do i use SR in IAR C?

Started by mehmet cihangir September 12, 2006
Hello,

I want to read Carry bit in Status Register. But i
didn't do. I wrote Inline assembler code in IAR C
codes like this;
asm("RLA.B &i2c_data");
and i want to read Carry bit after this code like
this;
if(SR.C)
.........
or
if(SR_bits.SR_C)
........
or
if(C)
.......

I will read Carry bit and change P1.5 pin, for
example if Carry bit is set i will set P1.5, if carry
bit is clear i will clear P1.5 , but i can't read
Carry bit and SR in IAR C compiler, i use
"io430x13x.h" header file and when i compile my codes
i am receiving "Error[Pe020]: identifier "SR" is
undefined" error msg. Why can't i read SR in IAR C
compiler? How do i check Carry bit in IAR C?
Can i do to assign directly Carry bit to P1.5 , like
this?
P1.5=C;
or
P1OUT_bit.P1OUT_5=SR_bit.SR_C;
is this possible?

Thanks,
__________________________________________________

Beginning Microcontrollers with the MSP430

--- In m..., mehmet cihangir wrote:
>
> Hello,
>
> I want to read Carry bit in Status Register. But i
> didn't do. I wrote Inline assembler code in IAR C
> codes like this;
> asm("RLA.B &i2c_data");

imho: MOV.W SR, int_variable
Or you could use the intrisic function __get_SR_register :

SR_reg = __get_SR_register();

Regards,

Fabio

----- Original Message -----
From: les_kamil
To: m...
Sent: Tuesday, September 12, 2006 5:08 AM
Subject: [SPAM] 6.1 [msp430] Re: How do i use SR in IAR C?
--- In m..., mehmet cihangir wrote:
>
> Hello,
>
> I want to read Carry bit in Status Register. But i
> didn't do. I wrote Inline assembler code in IAR C
> codes like this;
> asm("RLA.B &i2c_data");

imho: MOV.W SR, int_variable

------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.2/443 - Release Date: 11/9/2006
--- In m..., Fio Pereira wrote:
>
> Or you could use the intrisic function __get_SR_register :
>
> SR_reg = __get_SR_register();
>
> Regards,
>
> Fabio
i checked in crossworks (there isn't __get_SR_register() ):

xx=__get_register(0x02);
is compiled into:
MOV.W SR, R15
MOV.W R15, &_xx



Indeed, ANSI C doesn't provide for reading Carry flag, but if it did, it wouldn't be platform
independent of course...
If you want the Carry flag to set/clear a port pin, you don't need the _actual_ carry flag from
the status register.
Simply look at the bit that *will* cause a carry or not (can only be MSB or LSB):
Say you're shifting left, test the MSB for 1 or 0 _before_ you shift.
So :
if (variable & 0x80)
set_port_pin
else
clear_port_pin
SHIFT LEFT
... next bit... ?

Does that help ?

-- Kris
-----Original Message-----
From: m... [mailto:m...] On Behalf Of mehmet cihangir
Sent: Tuesday, 12 September 2006 5:33 PM
To: m...
Subject: [msp430] How do i use SR in IAR C?

Hello,

I want to read Carry bit in Status Register. But i
didn't do. I wrote Inline assembler code in IAR C
codes like this;
asm("RLA.B &i2c_data");
and i want to read Carry bit after this code like
this;
if(SR.C)
.........
or
if(SR_bits.SR_C)
........
or
if(C)
.......

I will read Carry bit and change P1.5 pin, for
example if Carry bit is set i will set P1.5, if carry
bit is clear i will clear P1.5 , but i can't read
Carry bit and SR in IAR C compiler, i use
"io430x13x.h" header file and when i compile my codes
i am receiving "Error[Pe020]: identifier "SR" is
undefined" error msg. Why can't i read SR in IAR C
compiler? How do i check Carry bit in IAR C?
Can i do to assign directly Carry bit to P1.5 , like
this?
P1.5=C;
or
P1OUT_bit.P1OUT_5=SR_bit.SR_C;
is this possible?

Thanks,
__________________________________________________
Wasn't your question about IAR C ??? At least, it is what is written on the subject of this message.

But your compiled code looks ok (despite using two instructions where could be just one).

Regards,

Fabio

----- Original Message -----
From: les_kamil
To: m...
Sent: Tuesday, September 12, 2006 9:00 AM
Subject: [SPAM] 6.1 [msp430] Re: How do i use SR in IAR C?
--- In m..., Fio Pereira wrote:
>
> Or you could use the intrisic function __get_SR_register :
>
> SR_reg = __get_SR_register();
>
> Regards,
>
> Fabio
i checked in crossworks (there isn't __get_SR_register() ):

xx=__get_register(0x02);
is compiled into:
MOV.W SR, R15
MOV.W R15, &_xx


------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.3/445 - Release Date: 11/9/2006




try

__intrinsic unsigned short __get_SR_register(void);

defined in intrinsic.h
----Original Message Follows----
From: mehmet cihangir
Reply-To: m...
To: m...
Subject: [msp430] How do i use SR in IAR C?
Date: Tue, 12 Sep 2006 00:32:38 -0700 (PDT)
MIME-Version: 1.0
X-Originating-IP: 68.142.206.128
X-Sender: m...@yahoo.com
Received: from n16a.bullet.scd.yahoo.com ([66.94.237.45]) by
bay0-mc10-f14.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2444); Wed,
13 Sep 2006 15:45:27 -0700
Received: from [66.218.69.2] by n16.bullet.scd.yahoo.com with NNFMP; 12 Sep
2006 07:32:41 -0000
Received: from [66.218.67.98] by t2.bullet.scd.yahoo.com with NNFMP; 12 Sep
2006 07:32:41 -0000
Received: (qmail 84552 invoked from network); 12 Sep 2006 07:32:40 -0000
Received: from unknown (66.218.66.166) by m41.grp.scd.yahoo.com with QMQP;
12 Sep 2006 07:32:40 -0000
Received: from unknown (HELO web33313.mail.mud.yahoo.com) (68.142.206.128)
by mta5.grp.scd.yahoo.com with SMTP; 12 Sep 2006 07:32:39 -0000
Received: (qmail 28097 invoked by uid 60001); 12 Sep 2006 07:32:38 -0000
Received: from [81.214.133.60] by web33313.mail.mud.yahoo.com via HTTP; Tue,
12 Sep 2006 00:32:38 PDT
X-Message-Info: LsUYwwHHNt1EQfPmSEgZuQO7+45iAPWUUO8S8Tw4JpcComment: DomainKeys? See http://antispam.yahoo.com/domainkeys
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=lima;
d=yahoogroups.com;b=sXQQQ3U0MXvbBG1oKfqqi3wrIVC+hFz1Q8klg/bUyTjPLVHsvEG53uPMJewm9HglvaCXXIPk9bAiq7a8lXdbv2U2vTFs2yAM/ons0vLXVLvaf3q4q1pdsMg9Czx0ctBL;
X-Yahoo-Newman-Property: groups-email
X-Yahoo-Newman-Id: 2342629-m27483
X-Apparently-To: m...
X-eGroups-Msg-Info: 1:0:0:0
Mailing-List: list m...; contact
m...
Delivered-To: mailing list m...
List-Id:
Precedence: bulk
List-Unsubscribe:
Return-Path:
sentto-2342629-27483-1158046361-htrada=h...@returns.groups.yahoo.com
X-OriginalArrivalTime: 13 Sep 2006 22:45:27.0435 (UTC)
FILETIME=[4ECDFDB0:01C6D786]

Hello,

I want to read Carry bit in Status Register. But i
didn't do. I wrote Inline assembler code in IAR C
codes like this;
asm("RLA.B &i2c_data");
and i want to read Carry bit after this code like
this;
if(SR.C)
.........
or
if(SR_bits.SR_C)
........
or
if(C)
.......

I will read Carry bit and change P1.5 pin, for
example if Carry bit is set i will set P1.5, if carry
bit is clear i will clear P1.5 , but i can't read
Carry bit and SR in IAR C compiler, i use
"io430x13x.h" header file and when i compile my codes
i am receiving "Error[Pe020]: identifier "SR" is
undefined" error msg. Why can't i read SR in IAR C
compiler? How do i check Carry bit in IAR C?
Can i do to assign directly Carry bit to P1.5 , like
this?
P1.5=C;
or
P1OUT_bit.P1OUT_5=SR_bit.SR_C;
is this possible?

Thanks,
__________________________________________________
Hernan Tradatti wrote:
> try
>
> __intrinsic unsigned short __get_SR_register(void);
>
> defined in intrinsic.h
mehmet cihangir Wrote:
> I want to read Carry bit in Status Register. But i
> didn't do. I wrote Inline assembler code in IAR C
> codes like this;
> asm("RLA.B &i2c_data");
> and i want to read Carry bit after this code like
> this;
> if(SR.C)
> ..........
> or
> if(SR_bits.SR_C)
> .........
> or
> if(C)
> ........
>
> I will read Carry bit and change P1.5 pin, for
> example if Carry bit is set i will set P1.5, if carry
> bit is clear i will clear P1.5 , but i can't read
> Carry bit and SR in IAR C compiler, i use
> "io430x13x.h" header file and when i compile my codes
> i am receiving "Error[Pe020]: identifier "SR" is
> undefined" error msg. Why can't i read SR in IAR C
> compiler? How do i check Carry bit in IAR C?
> Can i do to assign directly Carry bit to P1.5 , like
> this?
> P1.5=C;
> or
> P1OUT_bit.P1OUT_5=SR_bit.SR_C;
> is this possible?

As Hernan pointed out, it is possible to access the status register in C
using __get_SR_register(). However, I would strongly advice against it!

In C you have no control over when the status register is read, relative
to your inline assembler lines. This means that the carry flag bit could
have been destroyed by an other operation.

I would suggest that you try to rewrite the routine in a more C-like
faishon, or, if speed is crucial, rewrite it in assembler.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.