×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

8051 Code

8051 Code

8051 Code

(OP)
Hi.
Basically I need to implement the following code on an 8051 microcontroller:

If X < 10 THEN A<=B
         ELSE A<=C

Does anyone know how this might be achieved.  I know it has to so with conditional jump statements, but just not exactly how....

Any help would be greatly appreaciated

Thanks,
D

RE: 8051 Code

Mungovan,
   For the < 10 I always check z and c flags after a cjne instruction.  For the <= stuff, is that a pascal format for A = C, or the 'C' format for "A = A shifted C times"?  If the real question is the < 10, let me know, I have many macros made for ==, <=, <, >, >=, ect.  Including seperate macros for those pesky long jumps!!! i.e. if x < 10 jump really far away...
RCallaway

RE: 8051 Code

what is it "X" ?

mov A,X
subb X, #10h
jnc st
mov A,B
sjmp end
st:mov A,C
end: bla bla

RE: 8051 Code

barbari - Are you sure the carry flag is cleared before the subb instruction?  I don't think mov a,x clears it.  Also you have #10h, it should be decimal....  (typo)
Here is what I do:

                cjne    a, #10, Lab_x  ; Modify carry flag
Lab_x:          jnc     NotLessThan
                ajmp    LessThan
NotLessThan:    mov     a, b
                sjmp    TheEnd
LessThan:       mov     a, c
TheEnd:

Note -- be careful with the b, it's a real 8051 register..

Here is my macro, which gets rid of the bulky labels...
cjl             MACRO   X_, Y_, REL
                cjne    X_, Y_, $ + 3
                jnc     $ + 4
                ajmp    REL
ENDM

                cjl     a, #10, LessThan
                mov     a, b
                sjmp    theend
LessThan:       mov     a, c
theend:

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close