Electronics > Microcontrollers
Doubt in comparison routine
aless2056:
Doubt in comparison routine
Guys, I'm being beaten up to do the following asm routine for pic 16F877.
I have A and B, both range from 0 to 100 and I would like to do the following routine
If A = B, ok don't do anything in C
If A+5 > B, increase C
If A-5 < B, decrease C
ledtester:
--- Quote ---If A = B, ok don't do anything in C
If A+5 > B, increase C
If A-5 < B, decrease C
--- End quote ---
Are these cases supposed to be mutually exclusive because if, for instance, B = 10, A = 9 then what are you supposed to do with C?
DrG:
--- Quote from: ledtester on May 06, 2021, 02:24:41 am ---
--- Quote ---If A = B, ok don't do anything in C
If A+5 > B, increase C
If A-5 < B, decrease C
--- End quote ---
Note these cases are not mutually exclusive because if, for instance, B = 10, A = 9 then what are you supposed to do with C?
--- End quote ---
I'm reading it such the solution in C would be something like:
if(A<>B){
if(A+5>B){
C++;
}
else if (A-5<B){
C--;
}
}
I see that he wants asm code but I am too lazy to do someone else's homework, at least not until I see what they have tried first - actually whether it is homework or not.
aless2056:
I only want to increase or decrease C if the difference between A and B is 5 for one side or for the other side.
A = 50
...
B = 44, increment C
B = 45, increment C
B = 46, do nothing
...
B = 56, decrease C
B = 55, decrease C
B = 54, do nothing
DrG:
So what code do you have so far?
Navigation
[0] Message Index
[#] Next page
Go to full version