Author Topic: need help..on operation in Uc  (Read 3464 times)

0 Members and 1 Guest are viewing this topic.

Offline henryTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
need help..on operation in Uc
« on: August 06, 2007, 12:30:20 AM »
guys..
I want to make logic operation in Uc....but I stuck..

this the algorithm..:

I have 2 register...R0 and R1....and then..I want to compare them...
if R0 is bigger than R1 then decrement R0
if R0 is lower than R1 then increase R0...

I want to write in assembly language...

this is my program:

MAIN:
MOV A, R0
CJNE A,R1,CHECK
MOV P0,0FFH
MOV P2,0FFH

CHECK:
...................
...................

In the label check..I don't know how we can find that R1 is bigger or lower than R0..

can somebody help...

thanks..
   

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: need help..on operation in Uc
« Reply #1 on: August 07, 2007, 10:55:36 AM »
That'll depend on the MCU you are using. Not all assembly mnemonics are available in a specific MCU, some might rename the command you want.

If you're using an AVR try this site:
http://www.avr-asm-tutorial.net/avr_en/beginner/index.html
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: need help..on operation in Uc
« Reply #2 on: August 11, 2007, 11:17:18 AM »
why assembly and not C?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: need help..on operation in Uc
« Reply #3 on: August 13, 2007, 04:12:36 PM »
Hi,

I don't know how we can find that R1 is bigger or lower than R0..
Subtracting one from the other will yeild a positive or negative value (depending on ?C, might be reflected in a flag), if not zero of course.

In pseudo 'x86 code, it could be done something like this:
Code: [Select]
SUB  R0, R1
JZ   Do_Nothing
SUB  R0, R1
JNAE Increase_R0
DEC  R0
JMP DoNothing
Increase_R0:
INC  R0
Do_Nothing:
RET           ; or whatever
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here