A83: a bug in FP numbers code...
[Prev][Next][Index][Thread]
A83: a bug in FP numbers code...
I have been working on this, and have somehow encountered an error. This
program inputs 4 points, and from them derives the slope. Everything works
fine, except for the marked section. The following are a few input
scenarios and their results
X1= 1
Y1= 1
X2= 2
Y2= 2
Slope= 1
<it then pauses until a key is pressed, and exits correctly>
X1= 1
Y1= 2
X2= 1
Y2= 2
Slope= no slope
<it then pauses until a key is pressed, and exits correctly>
X1= 2
Y1=3
X2= 7
Y2= 15
Slope= 2.4
Slope=
<an error:overflow appears and the program is abnormally terminated>
If the slope is an integer, is displays only the integer.
If there is no slope, it prevents a divide by zero error and displays that.
If the slope is a decimal, it should display the decimal, and fractional
version...but does not.
Anyhelp would be appreciated,
Ted
;****************************************
.NOLIST
#define END .end
#define end .end
#define EQU .equ
#define equ .equ
#include "ti83asm.inc"
#include "tokens.inc"
;************************************************
;Moves floating point numbers around
#define FPmov(num_from,num_to) ld hl,num_from
#defcont \ ld de,num_to
#defcont \ call FPmov_asm
;************************************************
;System input routine
#define Input(prompt) ld hl,prompt
#defcont \ call input_asm
;************************************************
.LIST
_TOFRAC equ 48D5h
.org $9327
start:
call _runindicoff ;turn off the run indicator
call _clrScrnFull ;Clear Screen
call _homeup ;move cursor to 0,0
Input(px1) ;Input X1
FPmov(op1,x1) ;move from op1 to x1
Input(py1) ;Input Y1
FPmov(op1,y1) ;move from op1 to y1
Input(px2) ;Input X2
FPmov(op1,x2) ;move from op1 to x2
Input(py2) ;Input Y2
FPmov(y1,op2) ;move y1 to op2
call _FPSUB ;y2 - y1 -> op1
FPmov(op1,y1) ;move op1 to y1
FPmov(x2,op1) ;move x2 to op1
FPmov(x1,op2) ;move x1 to op2
call _FPSUB ;x2 - x1 -> op1
FPmov(op1,op2) ;move op1 tp op2
FPmov(op1,x1) ;move op1 to x1
call _CKOP2FP0 ;check if op2 = 0
jp z,no_slope ;if so, goto no_slope
FPmov(x1,op2) ;Move x2 into op2
FPmov(y1,op1) ;move y1 to op1
call _FPDIV ;y/x -> op1
FPmov(op1,x1) ;move the slope to x1
ld hl,slope ;load slope string
call _puts ;display it
call _formreal ;make op1 a string
ld hl,op3 ;op3 is start of string
call _puts ;Display the string
FPmov(x1,op1) ;Move the slope to op1
call _FRAC ;fpart(op1)->op1
FPmov(op1,op2) ;move op1 to op2
call _zerooop1 ;0->op1
call _cpop1op2 ;cp op1,op2
jp z,exit ;if int(op1) = op1
jp nz,fraction ;else
exit:
call _getkey ;wait until key is pressed
call _clrScrnFull ;clear the screen
call _homeup ;reset the cursor
ret ;exit the program
fraction:
call _newline ;move the cursor down a line
ld hl,slope ;load the slope string
call _puts ;display the slope string
;******Works fine until here******
;an Error: Overflow appears somewhere after
;*********************************
FPmov(x1,op1) ;move the slope to op1
call _tofrac ;convert op1 to frac
;op1 = numerator
;op2 = denominator
FPmov(op2,y2) ;move den. to y2
call _formreal ;turn op1 into string
ld hl,op3 ;load string into hl
call _puts ;display and update cursor
ld a,Lslash ;load a "/" into a
call _putc ;display and undate cursor
FPmov(y2,op1) ;move denom. into op1
call _formreal ;make op1 a sting
ld hl,op3 ;load that string into hl
call _puts ;display the string
jp exit ;goto exit
;*******Works Fine after here*********
;*************************************
no_slope:
ld hl,nslope ;Load the nslope string
call _puts ;Display it
jp exit ;goto exit
input_asm: ;*****************
ld de,$821C ; System Input
ld bc,16 ; Routine
ldir ;
ld a,1 ; Result in Op1
ld ($80C8),a ;
call $50B2 ;*****************
FPmov_asm: ;Copies FP var from hl to de
ld bc,9 ;9 bytes to copy
ldir ;copy them
ret ;return
;********************************
;Floating point variables
x1:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00
x2:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00
y1:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00
y2:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00
;*********************************
;Strings
px1:
.db "X",Lsub1,"= ",0
px2:
.db "X",Lsub2,"= ",0
py1:
.db "Y",Lsub1,"= ",0
py2:
.db "Y",Lsub2,"= ",0
slope:
.db "Slope= ",0
Nslope:
.db "Slope= no slope",0
end
.END