<p style="">In this section, we will see some bit manipulation operation using 8051. The 8051 supports some operations on different bits of an 8-bit number. The operations are like complementing, setting to 1, moving, ANDing, ORing etc.</p><p>In this example, we are taking a number AEH from location 10H, then after performing following bit related operations on that data, we are just storing the result at location 30H.</p><p style="">The bit related operations that will be performed on that data, are as follows &minus;</p><ul class="list"><li><p>Complement bit b<sub>2</sub></p></li><li><p>Move b<sub>5</sub>to b<sub>4</sub></p></li><li><p>OR b0and complement of b<sub>1&nbsp;</sub>and store to C (b<sub>7</sub>)</p></li><li><p>Set b<sub>6</sub></p></li><li><p>Reset bit b<sub>3</sub></p></li></ul><h2>Input is AEH</h2><table class="table table-bordered"><thead><tr valign="TOP"><th height="6" style="text-align: center;" width="100">BitPosition<br></th><th style="text-align: center;" width="14">b<sub>7</sub><br></th><th style="text-align: center;" width="14">b<sub>6</sub><br></th><th style="text-align: center;" width="14">b<sub>5</sub><br></th><th style="text-align: center;" width="14">b<sub>4</sub><br></th><th style="text-align: center;" width="14">b<sub>3</sub><br></th><th style="text-align: center;" width="14">b<sub>2</sub><br></th><th style="text-align: center;" width="14">b<sub>1</sub><br></th><th style="text-align: center;" width="14">b<sub>0</sub><br></th></tr></thead><tbody><tr valign="TOP"><td height="6" width="100">Value<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">0<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">0<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">0<br></td></tr></tbody></table><p><br></p><h2>Output</h2><table class="table table-bordered"><thead><tr valign="TOP"><th height="6" style="text-align: center;" width="100">BitPosition<br></th><th style="text-align: center;" width="14">b<sub>7</sub><br></th><th style="text-align: center;" width="14">b<sub>6</sub><br></th><th style="text-align: center;" width="14">b<sub>5</sub><br></th><th style="text-align: center;" width="14">b<sub>4</sub><br></th><th style="text-align: center;" width="14">b<sub>3</sub><br></th><th style="text-align: center;" width="14">b<sub>2</sub><br></th><th style="text-align: center;" width="14">b<sub>1</sub><br></th><th style="text-align: center;" width="14">b<sub>0</sub><br></th></tr></thead><tbody><tr valign="TOP"><td height="6" style="text-align: center;" width="100">Value<br></td><td style="text-align: center;" width="14">0<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">0<br></td><td style="text-align: center;" width="14">0<br></td><td style="text-align: center;" width="14">1<br></td><td style="text-align: center;" width="14">0<br></td></tr></tbody></table><p style=""><br></p><p style="">The output will be 72H</p><h2 style="">Program</h2><pre class="prettyprint notranslate">MOV24H,10H;Copy item from 10H to 24H CPL24.2;Complement bit b2 MOVC,24.5;Copy b5 to C MOV24.4,C;Move C to b4 MOVC,24.0;Make copy of b0 to C ORLC,/1;OR C and complement of b1 SETB24.6;Set bit b6 CLR24.3;Reset bit b3 MOV30H,24H; Store the result at 30H HALT: &nbsp; SJMP HALT</pre><p>From the program, we can easily get the logic. To use bit addressable operation, we have to access the location 20H to 2FH. These 16-bytes are used for bit addressable operations.&nbsp;</p><p>In Bit addressable operation, the Carry flag acts like the 1-bit accumulator.&nbsp;</p><h2>Output</h2><table class="table table-bordered" style="margin-left: calc(22%); width: 43%; margin-right: calc(35%);"><thead><tr valign="TOP"><th height="4" width="60">Address<br></th><th width="60">Value<br></th></tr></thead><tbody><tr valign="TOP"><td height="6" width="60"><div data-empty="true"><br></div><div data-empty="true"><br></div></td><td width="60">.<br>.<br>.<br></td></tr><tr valign="TOP"><td height="5" width="60">10H<br></td><td width="60">AEH<br></td></tr><tr valign="TOP"><td height="5" width="60">11H<br></td><td width="60"><div data-empty="true"><br></div><div data-empty="true"><br></div></td></tr><tr valign="TOP"><td height="6" width="60"><div data-empty="true"><br></div><div data-empty="true"><br></div></td><td width="60">.<br>.<br>.<br></td></tr><tr valign="TOP"><td height="5" width="60">30H<br></td><td width="60">72H<br></td></tr><tr valign="TOP"><td height="5" width="60">31H<br></td><td width="60"><div data-empty="true"><br></div><div data-empty="true"><br></div></td></tr><tr valign="TOP"><td height="4" width="60"><div data-empty="true"><br></div><div data-empty="true"><br></div></td><td width="60">.<br>.<br>.<br></td></tr></tbody></table> Bit Manipulation Program in 8051

Bit Manipulation Program in 8051



In this section, we will see some bit manipulation operation using 8051. The 8051 supports some operations on different bits of an 8-bit number. The operations are like complementing, setting to 1, moving, ANDing, ORing etc.

In this example, we are taking a number AEH from location 10H, then after performing following bit related operations on that data, we are just storing the result at location 30H.

The bit related operations that will be performed on that data, are as follows −

  • Complement bit b2

  • Move b5to b4

  • OR b0and complement of band store to C (b7)

  • Set b6

  • Reset bit b3

Input is AEH

BitPosition
b7
b6
b5
b4
b3
b2
b1
b0
Value
1
0
1
0
1
1
1
0


Output

BitPosition
b7
b6
b5
b4
b3
b2
b1
b0
Value
0
1
1
1
0
0
1
0


The output will be 72H

Program

MOV24H,10H;Copy item from 10H to 24H
CPL24.2;Complement bit b2
MOVC,24.5;Copy b5 to C
MOV24.4,C;Move C to b4
MOVC,24.0;Make copy of b0 to C
ORLC,/1;OR C and complement of b1
SETB24.6;Set bit b6
CLR24.3;Reset bit b3
MOV30H,24H; Store the result at 30H
HALT:   SJMP HALT

From the program, we can easily get the logic. To use bit addressable operation, we have to access the location 20H to 2FH. These 16-bytes are used for bit addressable operations. 

In Bit addressable operation, the Carry flag acts like the 1-bit accumulator. 

Output

Address
Value


.
.
.
10H
AEH
11H




.
.
.
30H
72H
31H




.
.
.
Updated on: 2020-06-27T12:54:00+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements