ARM Technical Support Knowledge Articles

SETTING OR CLEARING BITS IN THE ACCUMULATOR

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

How can I set or clear bits in the accumulator from my C code?

ANSWER

You must declare the SFR for the accumulator and you must create an SBIT for each bit you want to access. The following example program demonstrates this for bit 0 and bit 7.

sfr ACC = 0xe0;
sbit ACC_0 = ACC^0;
sbit ACC_7 = ACC^7;

void main (void)
{
ACC_0 = 1;
ACC_7 = 1;
}

The code generated for this function is:

             ; FUNCTION main (BEGIN)
                                           ; SOURCE LINE # 7
0000 D2E0              SETB    ACC_0
                                           ; SOURCE LINE # 8
0002 D2E7              SETB    ACC_7
                                           ; SOURCE LINE # 9
0004 22                RET
             ; FUNCTION main (END)

Article last edited on: 2001-04-27 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential