Name:
popram
Syntax:

POPRAM

 

Description:

Restore the contents of RAM 0-15 (variables b0-b15) from the 4 level 'RAM stack'. 

To reuse variables within a macro/sub-procedure it can be useful to 'free up' variables so that they can be reused as temporary variables within the macro. The pushram command pushs the contents of b0-b15 onto the ram stack so that they can then be reused for other purposes. The popram command then restores the original values at the end of the macro.

The 4-level stack used for pushram and popram is separate to the stack used for push and pop commands.

Applies To:
20X2, 28X2, 40X2
See Also:
Related Create:
    Share:
    Print:

    Protecting variable values

    Before calling a subroutine a 'pushram' is executed so variables can be restored, if the subroutine uses those variables and alters their values. After the subroutine completes a 'popram' must be executed to restore the original variable values as they were previously.

    Code Example:
    main:	for b1 = 1 to 5
    	  sertxd( "Before gosub, b1=", #b1, cr, lf )
    	  pushram
    	  gosub mysub
    	  popram
    	  sertxd( "After gosub, b1=", #b1, cr, lf, cr, lf )
    	next
    	end
    	
    mysub:	b1 = 99	
    	sertxd( "   Inside mysub, b1=", #b1, cr, lf )
    	return
    Copy Code Submit an Example

    Use within subroutine

    On entry into the subroutine a 'pushram' is used to allow re-use of variables within the routine. At the end of the routine, before any return, a 'popram' must be executed to restore the original variable values as they were outside the subroutine.

    Code Example:
    main:	for b1 = 1 to 5
    	  sertxd( "Before gosub, b1=", #b1, cr, lf )
    	  gosub mysub
    	  sertxd( "After gosub, b1=", #b1, cr, lf, cr, lf )
    	next
    	end
    	
    mysub:	pushram
    	b1 = 99	
    	sertxd( "   Inside mysub, b1=", #b1, cr, lf )
    	popram
    	return
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.

    Comments

    • Login to leave a comment.