Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me analyse my RLC codes

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,689
Hi

I want to make sure that Im right the codes espeically RLC:



Code:
SIGNAL EQU P1.0;

LOOP:  MOV B,#8
           MOV A,#FFH
           RLC A
           MOV SIGNAL,C
           DJNZ B,LOOP

I understand that C denotes as Carry so every loop, the single on the left of A (FF#) will be shifted and the bit will be stored in the Carry bit.
What happen to the right bit? will zero appear in the far right end of the A?

For example

11111111 c=0
11111110 c=1
11111100 c=1
11111000 c=1
11110000 c=1
11100000 c=1
11000000 c=1
10000000 c=1
00000000 c=1

Is my example correct?

Maverick Max
 

Re: RLC - Help

The original state of the carry flag moves into the bit 0 position of the A, after each shift.

Thus not "0" is coming into bit 0 (the far right end of the A) for each shift.
 

Re: RLC - Help

Ok where didthe bit go to? Accmulator?

11111111 c=0 Acc=0
11111110 c=0 Acc=1
11111100 c=0 Acc=1
11111000 c=0 Acc=1
11110000 c=0 Acc=1
11100000 c=0 Acc=1
11000000 c=0 Acc=1
10000000 c=0 Acc=1
00000000 c=0 Acc=1

Please correct if I make mistake

Maverick Max
 

Re: RLC - Help

Hi Maverickmax,

The Accumulator is a 8 bit register in 8051 series.

RLC means Rotate Left through Carry

The bits are rotating to the left through carry flag bit.

Code:
  --------------------------->>>>-------------
 |                                            |
 |                                            |
  ---<<<---- CY--------11111111---<<<---------

Thus before receiving the bit 7 of Accumulator, the Carry flag send his value to bit 0 of Accumulator.
Obvious during RLC the bits inside A are shifted one position to the left.

If Carry hold "0" before the first movement, that's why you see the "0" filling the Accumulator from the right

11111111
11111110
11111101
11111011
11110111
11101111
11011111
10111111
01111111
11111111
11111110

and so on

It's quite simple.

But if you want that your code to work properly and not an endless loop, place the label LOOP two rows bellow than it's now wrote.

Code:
SIGNAL EQU P1.0; 

           MOV B,#8 
           MOV A,#FFH 
LOOP:  RLC A 
           MOV SIGNAL,C 
           DJNZ B,LOOP
 

    Maverickmax

    Points: 2
    Helpful Answer Positive Rating
Re: RLC - Help

Dear me!

I get it now - I just gave you 'Helped me' point

Thank you

Maverickmax
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top