Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

8051 Code

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE
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
 
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 &quot;A = A shifted C times&quot;? 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

 
what is it &quot;X&quot; ?

mov A,X
subb X, #10h
jnc st
mov A,B
sjmp end
st:mov A,C
end: bla bla
 
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:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top