Difference between revisions of "PM Opc RET"

From SublabWiki
Jump to: navigation, search
(RET* takes 16 cycles)
 
Line 30: Line 30:
 
  V = Memory[SP+2]
 
  V = Memory[SP+2]
 
  PC = (Memory[SP+1] SHL 8) + Memory[SP]
 
  PC = (Memory[SP+1] SHL 8) + Memory[SP]
  SP = SP - 3
+
  SP = SP + 3
  
 
  ; RETI (Return from an interrupt)
 
  ; RETI (Return from an interrupt)
Line 37: Line 37:
 
  PC = (Memory[SP+2] SHL 8) + Memory[SP+1]
 
  PC = (Memory[SP+2] SHL 8) + Memory[SP+1]
 
  F = Memory[SP]
 
  F = Memory[SP]
  SP = SP - 4
+
  SP = SP + 4
  
 
  ; RETSKIP (Return from a subroutine and skip 2 bytes)
 
  ; RETSKIP (Return from a subroutine and skip 2 bytes)
Line 43: Line 43:
 
  V = Memory[SP+2]
 
  V = Memory[SP+2]
 
  PC = (Memory[SP+1] SHL 8) + Memory[SP] + 2
 
  PC = (Memory[SP+1] SHL 8) + Memory[SP] + 2
  SP = SP - 3
+
  SP = SP + 3
  
 
=== Description ===
 
=== Description ===

Latest revision as of 22:04, 15 May 2011

RET = Return from routine

Hex Mnemonic Cycles
F8 RET 16
F9 RETI 16
FA RETSKIP 16

Execute

F        = Register F
U/V      = Register U or V
SP       = Register SP (Stack Pointer)
PC       = Register PC (Program Counter)
; RET (Return from a subroutine)

V = Memory[SP+2]
PC = (Memory[SP+1] SHL 8) + Memory[SP]
SP = SP + 3
; RETI (Return from an interrupt)

V = Memory[SP+3]
PC = (Memory[SP+2] SHL 8) + Memory[SP+1]
F = Memory[SP]
SP = SP + 4
; RETSKIP (Return from a subroutine and skip 2 bytes)

V = Memory[SP+2]
PC = (Memory[SP+1] SHL 8) + Memory[SP] + 2
SP = SP + 3

Description

Return from a subroutine or an interrupt.

Conditions

None

Examples

 ; A = 0x10
 ; B = 0x10
 CALL somefunction
 ; A = 0x11
 ; B = 0x0F

 (...)

somefunction:
 INC A
 DEC B
 RET
 INC A  ; Never executed

« Back to Instruction set