Doubt in comparison routine

Thread Starter

massanetabr

Joined Jun 3, 2019
23
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
 

Thread Starter

massanetabr

Joined Jun 3, 2019
23
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
 

atferrari

Joined Jan 6, 2004
4,321
I always work out the flow diagram and once satisfied with it, I write the code. This last becomes a simple clerical task.
 

Robin66

Joined Jan 5, 2016
272
The pseudo code is:

if(A+5 > B)
C++;
else if(A-5 < B)
C--;
end

This is enough for you to attempt to write the asm
 

click_here

Joined Sep 22, 2020
177
I think that the problem that the op was having is that there is no < or > in the PIC assembly language.

To work out if it's < or > the user needs to subtract one number from the other and see if the zero/carry bit is set in the status register
 

cmartinez

Joined Jan 17, 2007
7,332
The OP has probably already seen through that and solved the problem. It would be real nice if he were to report back and post his solution out of simple courtesy, though.
 
Top