Society of Robots - Robot Forum

Software => Software => Topic started by: henry on August 06, 2007, 12:30:20 AM

Title: need help..on operation in Uc
Post by: henry 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..
   
Title: Re: need help..on operation in Uc
Post by: rgcustodio 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 (http://www.avr-asm-tutorial.net/avr_en/beginner/index.html)
Title: Re: need help..on operation in Uc
Post by: Admin on August 11, 2007, 11:17:18 AM
why assembly and not C?
Title: Re: need help..on operation in Uc
Post by: Soeren 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