Jump to content

8051 - register select code (not RS0, RS1)

- - - - -

  • Please log in to reply
No replies to this topic

#1
existentialist

existentialist

    Newbie

  • Members
  • PipPip
  • 14 posts
I wrote this program that repeatedly divides values from 1 register to 2.
something like this:

R7 = 255

while(R7 != 0)

{

    if( aBit == 1)  {

        R7--

        R0++

    }

    else {

        R7--

        R1++

    }

}

Here is my assembly code:
I'm using 00 bit to divide to either R0, or R1

ORG 00


MOV R7, #0FFh

loop: JNB 00, incr0

ACALL incr1

endLoop: DJNZ R7, loop



here: SJMP here


incr0: INC R0

SETB 00

SJMP endLoop


incr1: INC R1

CLR 00

RET


END

What i want to do is generalize this solution for use with a n-bits
I have this code using 2 bits (00 and 01) to divide to R0, R1, R2,R3
i can't figure out how to set up the logic for it
i'm guessing something like:

if (!00 && !01) {}

else if (!00 & 01) {}

else if (00 & !01) {}

else {}

Here is my code so far:

ORG 00

SJMP main

main: MOV A, #0

MOV R0, A

MOV R1, A

MOV R2, A

MOV R3, A


restart:MOV R4, #0FFh


loop: 

JNB	00, skip

SETB 00

skip: ..........

ACALL incr

DJNZ R4, loop



incr: JBC 00, overflow

SETB 00

SJMP term


overflow: JBC 01, clear

SETB 01

SJMP incr


clear: CLR 00

term: RET


END

Any help is greatly appreciated.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users