OP Math

z80 » Variables

TI has given us the addresses of most of the math routines. You can use these routines to make some useful math programs. Let me begin by saying that if you're going to be making programs that do huge amounts of calculation, you probably want to go ahead and just use TI-BASIC. Asm is a lot faster most of the time but it's a heck of a lot easier to make a math program in TI-BASIC than in asm. Just look at the TI-BASIC versus Asm Chart, you can see that it's easier to add, subtract, multiply, divide, and store numbers in TI-BASIC. Just storing .5 as A is somewhere around 50 bytes in asm but only 3 or 4 in TI-BASIC.

Before beginning, make sure you have the include file ti86math.inc. It's also included in Includes.zip. This include file will give you the equates for the many Math Functions TI has given us. The comments in the file explain the inputs and outputs of each function.

You can pretty much teach yourself this section. All you have to do is look at some source and you'll get the basic idea. Let's try letting the uesr input a number and display the square root of it. Download it to see what it looks like in action.

#include "ti86asm.inc"		;normal include file with
				; common ROM calls
#include "ti86math.inc"		;contains math function
				; equates
_formDisp	=$515b
_ioprompt	=$c324
_asap_ind	=$d623
.org _asm_exec_ram
	call _clrScrn		;clear screen & text memory
	ld bc,0*256+0		;row 0, col 0
	ld (_curRow),bc
	ld hl,string		;string to prompt with
	call input		;input number and store
				; in OP1
	call _SQRoot		;$54ac - op1 = square root
				; of op1
	jp _formDisp		;$515b - displays op1 right
				; justified big numbers
				;aka _dispOP1
input:				;14 byte routine to input
				; numbers
				;ti was nice enough to
				; give us the basics of
				; this routine
	ld de,_ioprompt		;$c324 - string storage for
				; display when prompted
	call _mov10b		;$427b - move 10 bytes from
				; hl to de
	ld a,$0d		;type of input
				;$0d - value
				:$0c - string
	ld (_asap_ind),a	;$d623 - tell ti86 what kind
				; to be inputted
	jp _exec_pg3		;$5714 - ti86 os input
				; routine of type
				; (_asap_ind) with all ti-os
				; key handler routines
				;inputted value/string stored
				; in op1
string: .db "number? ",0	;string to prompt with
.end


More from z80 » Variables
Absolute Addressing // Binary Coded Decimal // Creating Variables // External Levels // _FindSym // Messing with Variable Data // OP Math // TI-OS Variable Manipulation // Variable Name Format // VAT Searches