ASM Modules; ; 10/20/97 ; ASM MODULES ----------- This document is intended to show how to have ASM programs call directly to another ASM program, allowing for the generation of ASM modules. The use of modules will be needed if aa ASM 'package' size is too large to be executed as a single program. The available space for ASM execution on the TI86 is around 9000 bytes. However this availble size can be lessened by installing TI-Aplets that may steal some of this space. The mechanism to allow an ASM program call another ASM program is designed to make it as easy and 'seamless' as possible. It is mimicked after the way a TI86 'Basic' program executes another TI86 'Basic' program. Overview of what happens: ------------------------ - Name of ASM program to execute is sent to the 'execute' routine - The current values of all the Z80 registers are save to RAM so that they can be used by the called ASM module, parameter passing. The 'flag' register 'F' is also saved. - The program to execute is checked to make sure that it is in fact an ASM program. - The name of the current ASM program is saved somewhere secret. - The new ASM program is loaded. - The ASM program is executed. *************************************** * After completion of the ASM module *************************************** - The calling ASM program is loaded back into the ASM execution area. - The contents of 'OP1', and OP2 if complex number, contain the value(s) set at the end of the called routine. - The Z80 registers will be set to the values that they were when the called routine completed. - Execution resumes in the calling routine. ; ;***************************************************************** ; ; _exec_assembly : load and execute the Z80 program that ; is stored in the TI-86 program whose ; name is in OP1. ; ; input : ; OP1 = var name of program to execute ; ; Z80 registers passed to called program ; ; output : ; OP1/OP2 outputted from called program ; ; Z80 register values set by called program ; ; calling program reloaded into ASM execution area ; ;***************************************************************** ; ; The Z80 register values are passed to the called program in ; these RAM locations: ; ; _asm_reg_af equ 0D624h _asm_reg_bc equ 0D628h ; _asm_reg_a equ 0D625h _asm_reg_c equ 0D628h ; _asm_reg_b equ 0D629h ; _asm_reg_hl equ 0D626h ; _asm_reg_l equ 0D626h _asm_reg_de equ 0D62Ah ; _asm_reg_h equ 0D627h _asm_reg_e equ 0D62Ah ; _asm_reg_d equ 0D62Bh ; ; ; EX : ld hl,(_asm_reg_hl) ; hl = saved hl ; ld a,(_asm_reg_l) ; a = saved l ; ; inorder to get the flag register into f : ; ; ld hl,(_asm_reg_af) ; push hl ; pop af ; sets acc and flag status ; ; MODULE USE EXAMPLE: ------------------ - asm_prog1 will call to asm_prog2 - asm_prog2 will set OP1 to either floating point 1 or 2 - asm prog2 will set the Z80 registers to some values ;************************************************************************* ; org _asm_exec_ram ; asm_prog1: ld hl,prog2name-1 call _mov10toop1 ; op1 = name of 2nd asm prog to call ; ld a,1 ; signal set OP1 = 1 call _exec_assembly ; make call to execute 2nd asm ; ; prog2 returns the following values: ; ; OP1 = floating point 1 ; a = 1 ; bc = 0ffffh ; de = 1111h ; hl = 2222h ; ld hl,prog2name-1 call _mov10toop1 ; op1 = name of 2nd asm prog to call ; ld a,2 ; signal set OP1 = 2 call _exec_assembly ; make call to execute 2nd asm ; ; prog2 returns the following values: ; ; OP1 = floating point 2 ; a = 1 ; bc = 0ffffh ; de = 1111h ; hl = 2222h ; ret ; end of prog1 ; prog2name: db 5,'PROG2' ; name of ASM program to call ; ;************************************************************************** ; ; ********************************************************************** ; ; org _asm_exec_ram ; asm_prog2: ld a,(_asm_reg_a) ; get input acc cp 1 ; test for 1 push af ; save status call z,_op1set1 pop af ; status call nz,_op1set2 ; ld a,1 ; send back to calling prog ld bc,0ffffh ; send back to calling prog ld de,1111h ; send back to calling prog ld hl,2222h ; send back to calling prog ; ret ; end of prog2 ;************************************************************************* TI-86 Assembly Programming |
(c) Copyright 1998 Texas Instruments Incorporated. All rights reserved.