compare and branch problem

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I try to use the branch instruction

 cp r16,r7
 brlo rtem3

  •  that is not working.. if instead of this i use a constant number
  • cpi r16,0x08
  • brlo rtem3
  • then it works! ( r16 contains  a variable)
  • what i have done wrong ?
  • thank you in advance
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how do you put 0x08 into r7 ? 

remember that ldi don't work on r0-r15

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i did

ldi r16,0x08

mov r7,r16

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you show the full code not just dribs and drabs. Presumably after you use R16 to get the 0x08 into R7 you then did something else to get another value into R16? Otherwise they both have 0x08 at the point of the CP.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

of course r16 have the number of an ADC  conversion ..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

athmio wrote:
of course
Do you believe that readers here are psychic? How could anyone but you reading this thread know that an ADC were involved?? You still haven't shown the code or, for that matter, actually said what "  not working..  " actually means??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

when i use the same code but with the instruction << cpi >> everything are good when i use with <<cp >> no ...r16  has in both situations the same code that gave it the number What is more i stop the program and i <<ask>> AVR to out portb what it has in r16 -r7 and they have what it is supposed to have!

Last Edited: Tue. Mar 19, 2019 - 10:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR opcodes are deterministic. The only thing that can possibly be different here is the input data. That's why it's so important for you to show how you are deriving your input data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

athmio wrote:

when i use the same code but with the instruction << cpi >> everything are good when i use with <<cp >> no ...r16  has in both situations the same code that gave it the number What is more i stop the program and i <<ask>> AVR to out portb what it has in r16 -r7 and they have what it is supposed to have!

 

What you are saying is that the cp instruction doesn't work. This is basically not possible, unless you are running the CPU out of spec, like overclocking, undervoltage, noisy clock or whatever.

So r7 doesn't have the value you think it has. Maybe it was changed by an interrupt?

 

Give us the smallest possible complete program that reproduces the problem and we will try to test it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

as soon as i will be with my computer i send you the code.. thank you anyway