;; ;; $Id: table.asm,v 1.2 2001/03/05 03:43:54 james Exp $ ;; ;; table.asm, functions for processing tables within a stack architecture. ;; Copyright (C) 2001 James Cameron (quozl@us.netrek.org) ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; ;;; ;;; execute ;;; ;;; Given a program address on the data stack, transfer execution to ;;; it by moving the value to the PCL register. The RETURN in the ;;; callee will return to the caller. ;;; execute ; ( d -- ) popf pclath popw movwf pcl ;;; ;;; per ;;; ;;; Given a handler entry point and a table, call the handler once for ;;; each byte in the table, with the stack containing the byte. ;;; The handler will consume the byte. ;;; per ; ( handler.d table.d -- ) pushl 0 ; initialise offset per_loop ; ( handler.d table.d offset ) ; reorder stack for execute call dup ; ( handler.d table.d offset offset ) picks 3 picks 3 call execute ; get the byte from the string ; ( handler.d table.d off ) w=byte iorlw 0 ; is zero? bz per_exit ; if so, exit loop pushw ; ( handler.d table.d off byte ) picks 5 picks 5 ; ( handler.d table.d off byte handler.d ) call execute ; ( handler.d table.d off ) incf indf,f ; increment offset goto per_loop per_exit ; ( handler.d table.d off ) pops 5 return ;;; ;;; pers ;;; ;;; Construct a call to per given a function and a table pointer. ;;; pers macro function,table pusha function pusha table call per endm