What's the difference between "JMP" commands and "CALL" comands?

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

For instance I can't figure out why we have the command "CALL" when the command "JMP" do the same and takes less clocks? 🙃

Last Edited: Wed. Jun 22, 2022 - 06:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you need to study the attached document. It answers ALL you questions in some detail.

 

 

Attachment(s): 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

With my moderator hat on: Are you trolling?

 

Anyway the answer is on has the potential to come back the other doesn't.

 

The long answer is that when you JMP all that really happens is the destination address is loaded into the PC register and execution continues form there.

 

But if you CALL the same thing happens and PC is loaded with the address given in the CALL instruction. However in addition the address of the next opcode after the CALL is PUSHd onto the stack (2 bytes most AVRS, 3 bytes for ones with large address space). Then the destination is loaded into PC and execution continues. However there is another opcode used in conjunction with CALL and that is RET (for RETurn). At the end of the new sequence of code the programmer can place a RET and when that is executed the rurren top of the stack (and hopefully that still means the address that was PUSHd and the time of the CALL is POPd and placed into the PC register So now execution continues back at the opcode after the original CALL.

 

When you call functions in C:

int add(int a, int b) {
    return a + b;
}

int main(void) {
    PORTB = add(13, 29);
    PORTC = 0x55;
}

then in main() when it reaches the invocation of add() it will "CALL add" which puts the address of the add: function into PC and it continues there. When add() has finished the arithmetic and performs "return" (or sometimes that is just implied by the last '}' in he function) it executes RET and comes back to the PORTC= operation after the PORTB=add() stuff completed.

Last Edited: Wed. Jun 22, 2022 - 11:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank for the document. That's really helpfull.  I just was looking at the "Instruction Set Summary" which is at the end of the datasheet and the difference is not clear if you look only that page. 

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

Thank you, that's clear now yes

 

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


Vladimir101 wrote:
"Instruction Set Summary"
Did you spot the word "summary" in there? It's not the complete detail. As you've already found out:

 

 

but: