BRNE beginners question.

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

I am using the Arduino IDE and an Uno to learn the basics of AVR assembler.

 

I have the following code. It works fine except the changes I make in the "Donner2" subroutine are not reflected in the final Z.

 

I have been mucking around with this for an hour now.. any help as to what i am doing wrong is much appreciated!!

 


        LDI      ZL         ,  lo8(   Table2   )   //   Z  at element 0
        LDI      ZH         ,  hi8(   Table2   )   //   Z at element  0
        ADIW     Z          ,  5                   //   increment to element 5
        LDI      R16        ,  0                   //   
        LDI      R17        ,  23                  //   


        // NOTE!  If I RET here I will have array element position 5 as expected.


        
        RCALL    Check4
        LPM      R24        ,  Z                   //   
        
        // NOTE!  This returns the value in array element 10, I expected the value in element 14
        RET



Check4:
        
        CP       R16        ,  R17
        BRNE     Donner2                // branch if EQUAL  

        // these 2 ADIWs are not in the final value!!       
        ADIW     Z          ,      1   // increment to element 11
        ADIW     Z          ,      3   // increment to element 14
          
        RET




Donner:
        RET



Donner2:
  
        ADIW     Z          ,      5  // increment Z by 3
        RET
        
            
               

 

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Correction: It works fine but the ADIWs after the BRNE are not reflected in the final value for Z

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Those ADIW are unreachable. When the BRNE jumps to Donner2, the return will be to the LPM...

David (aka frog_jr)

Last Edited: Sat. Dec 2, 2017 - 12:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

frog_jr:

 

 

Thank you for a quick and clear answer.  What could I do differently to it can be reached? What I am trying to do is just play with nested function calls and make sure I understand them and how to call / return properly.

 

 

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

CPSE   R16, R17

RCALL Donner2 

 

 

seems to do it.

 

Thank you frog_jr!!

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Perhaps something like:

    CP       R16, R17
    BREQ     RegsEqual    // branch if EQUAL
    CALL     Donner2      // Increment by 5

Regs_Equal:
    ADIW     Z, 1       // increment to element 11 if R16 != R17, else element 6
    ADIW     Z, 3       // increment to element 14
    RET

Donner:      // Not used
    RET

Donner2:
    ADIW     Z, 5       // increment Z by 5
    RET

This will branch to Donner2 if R16 == R17 and then return to LPM

This will call Donner2 and then continue to the two ADIW if R16 != R17.

 

Edit: you figured it out while I was typing...smiley

David (aka frog_jr)

Last Edited: Sat. Dec 2, 2017 - 12:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One final question:

 

CPSE is compare and skip if equal. 

 

I can not find any "compare and skip if NOT equal" directly as an opcode.  Does such an animal exist?

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Does such an animal exist

Not on AVR, and that has been the subject of much grumbling around here over the years.  E.g.:

https://www.avrfreaks.net/forum/cpse-instruction

https://www.avrfreaks.net/forum/use-cpse-instruction
https://www.avrfreaks.net/comment/1083171#comment-1083171

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Joey:

 

Thank you for the help!

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.