what does JMP do to stack and frame pointers?

When an assembly has an instruction like jmp f what happens to the stack and frame pointers?

I mean - f is a label in memory right? How can we jump to different address in memory and not update our frame and stack pointers...

EDIT: I am talking about Intel x86 assembly yes :)


The stack and frame pointers deal with location of the data . jmp instructions deal with location of the code . Unless something drastic happens, one should not affect the other. Here's a list of drastic things:

  • Task switches - due to a far jump using a task gate
  • faults - due to a jump to a new page that is invalid, or jumping out of the current segment, or a jmp that tries to change the privilege illegally.
  • traps - for instance, due to a code breakpoint. In fact, no other trap comes to mind at the moment.
  • That's about it. Even those cases change the stack because they involve some sort of context switch, either to a new task or to some exception handler.

    Note also that no OS that I know of uses the CPU's task switching features. It's usually implemented in software.


    I'll guess you're talking about the Intel instruction? In that case, nothing happens to any stack/frame pointers, the code just continues execution in the same context but at the new address.

    I guess that answer has some caveats - it is possible to cause a task switch using the jmp instruction, in which case all kinds of crazy stuff might happen. You'll probably want to read the documentation for all the details. The Intel Software Developer's Manual has all the details:

  • jmp documentation in Volume 2A
  • 7.3 Task Switching in Volume 3A
  • Edit: referring to your question about jumping without updating.

    You have to be able to jump around your code without modifying the stack & frame pointers. It's the same as goto in C code, for example - you can hop all over your function without needing to modify the execution context at all.


    How can we jump to different address in memory and not update our frame and stack pointers...

    Because the instruction pointer (eip) is stored in a different register from the frame and stack pointers (esp, ebp). Changing one won't affect the others (normally).

    链接地址: http://www.djcxy.com/p/82374.html

    上一篇: 分段寄存器使用

    下一篇: JMP对堆栈和帧指针做了什么?