CS232, Spring 2008, JVM2 Project
How return works in the JVM2
Here are the microinstructions that implement the return instruction, with comments added to help explain what is happening.
; dispose of the subroutine's stack frame. In other words, restore sp to point to the top of the caller's stack frame.
lv->sp
dec4-sp
; put the return address into the pc register
lv->mar
mdr<-Stack[mar]
mdr->mar
mdr<-Stack[mar]
mdr->pc
; restore lv to point to the bottom of the caller's stack frame
inc4-mar
mdr<-Stack[mar]
mdr->lv
; if the stack is not empy, update the TOS to match the top of the stack
sp<0?skip2
mdr<-Stack[sp]
mdr->tos
End