Difference between revisions of "Snippet:KStack"

From veswiki
Jump to: navigation, search
 
Line 4: Line 4:
 
;===========================================================================
 
;===========================================================================
 
; the K stack implements a stack using the registers. it uses r63 as a stack
 
; the K stack implements a stack using the registers. it uses r63 as a stack
; pointer that holds the register number of the top of the stack, starting
+
; pointer that holds the register number of the top of the stack.
; at r57 and working down. when called, K is pushed to the first two
+
; When called, K is pushed to the first two registers on the stack, and the  
; registers on the stack, and the pointer is increased.
+
; pointer is increased.
 
;
 
;
 
; at startup, the stack pointer (r63) should be set to 62 ($3E)
 
; at startup, the stack pointer (r63) should be set to 62 ($3E)
Line 14: Line 14:
 
;---------------------------------------------------------------------------
 
;---------------------------------------------------------------------------
 
; pushes register K onto the stack using r63 as the stack pointer
 
; pushes register K onto the stack using r63 as the stack pointer
; destroys ISAR
+
; destroys ISAR data
  
kstack.push:
+
pushk:
; get the top of the stack
+
lisu 7 ; get the top of the stack
lisu 7
+
lisl 7 ; r63, stack pointer
lisl 7 ; r63, stack pointer
+
lr A,S
lr A, S
+
lr IS, A ; load the referenced register
lr IS, A ; load the referenced register
+
lr A,KU
; push K onto the stack
+
lr I,A ; push high byte of K
lr A, Ku
+
lr A,KL
lr D, A ; push high byte of K
+
lr I,A ; push low byte of K
lr A, Kl
+
lr A,IS
lr S, A ; push low byte of K
+
lisu 7
; adjust the stack pointer
+
lisl 3
lr A, IS
+
lr S,A ; save the register number to the stack pointer
ai $ff ; decrease ISAR
+
pop
lisu 7
 
lisl 7
 
lr S, A ; store the adjusted stack pointer in r63
 
 
 
; return from the subroutine
 
pop
 
  
 
;---------------------------------------------------------------------------
 
;---------------------------------------------------------------------------
Line 43: Line 37:
 
; destroys ISAR
 
; destroys ISAR
 
                  
 
                  
kstack.pop:
+
popk:
; retrieve K from the stack
+
lisu 7 ; r63, stack pointer
lisu 7
+
lisl 7
lisl 7
+
lr A,S ; A = stack pointer, points to next free
lr A, S ; load the stack pointer into A
+
ai $ff ; A = last pushed byte, KL
inc ; increment the pointer
+
lr IS,A ; ISAR -> KL
lr IS, A ; and set the ISAR
+
lr A,D ; read KL, then ISAR -> KU
lr A, I
+
lr KL,A
lr Kl, A ; load lower byte of K
+
lr A,S ; read KU
lr A, S
+
lr KU,A
lr Ku, A ; load upper byte of K
+
lr A,IS ; ISAR now points to new stack pointer
; adjust the stack pointer
+
lisu 7
lr A, IS
+
lisl 3
lisu 7
+
lr S,A ; store new stack pointer in r59
lisl 7
+
pop
lr S, A ; store the adjusted stack pointer in r63
 
 
 
; return from the subroutine
 
pop
 
 
</pre>
 
</pre>

Latest revision as of 20:25, 5 August 2026

;===========================================================================
; KStack Functions
;===========================================================================
; the K stack implements a stack using the registers. it uses r63 as a stack
; pointer that holds the register number of the top of the stack.
; When called, K is pushed to the first two registers on the stack, and the 
; pointer is increased.
;
; at startup, the stack pointer (r63) should be set to 62 ($3E)

;---------------------------------------------------------------------------
; KStack Push
;---------------------------------------------------------------------------
; pushes register K onto the stack using r63 as the stack pointer
; destroys ISAR data

pushk:
		lisu	7				; get the top of the stack
		lisl	7				; r63, stack pointer
		lr	A,S
		lr	IS, A				; load the referenced register	
		lr	A,KU
		lr	I,A				; push high byte of K
		lr	A,KL
		lr	I,A				; push low byte of K
		lr	A,IS
		lisu	7
		lisl	3
		lr	S,A				; save the register number to the stack pointer
		pop

;---------------------------------------------------------------------------
; KStack Pop
;---------------------------------------------------------------------------
; pops register K from the stack using r63 as the stack pointer
; destroys ISAR
                
popk:
		lisu	7				; r63, stack pointer
		lisl	7
		lr	A,S				; A = stack pointer, points to next free
		ai	$ff				; A = last pushed byte, KL
		lr	IS,A				; ISAR -> KL
		lr	A,D				; read KL, then ISAR -> KU
		lr	KL,A
		lr	A,S				; read KU
		lr	KU,A
		lr	A,IS				; ISAR now points to new stack pointer
		lisu	7
		lisl	3
		lr	S,A				; store new stack pointer in r59
		pop