A83: Help with a problem


[Prev][Next][Index][Thread]

A83: Help with a problem




I have encountered a bug in the following code that I can not figure out.  
This program checks whether or not a number is a perfect square, and if it 
is, display the square root.  It can detect if the number is a perfect square 
or not, but when it displays the square root, it has a problem.  When I enter 
in 4 it outputs 1.41421356 E -36 and that really isn't the square root of 4.  
Any help will be appreciated, as well as optimizations.  Here is the code:

.NOLIST
#define END .end
#define end .end
#define EQU .equ
#define equ .equ
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
PGMIO_EXEC equ 50B2h
_formDisp equ 4D0Eh
.org $9327
    call _clrScrnFULL          ;Clears the screen
    call _homeup                 ;Sets cursor to 0,0
    ld de,821ch                   ;*********************
    ld hl,prompt                      ;
    ld bc,16                            ;System Input Routine
    ldir                                  ;
    ld a,1                            ;stores result in Op1
    ld (ASM_IND_CALL),a    ;
    call PGMIO_EXEC       ;*********************
                                          ;The following checks if
                                          ;the input is a perfect
                                          ;Square while saving
                                ;op1 in op3 for further use
                                          ;
    call _op1toop3               ;op1 -> op3
    call _sqroot                   ;square root of op1 -> op1
    call _frac                       ;fpart(op1) -> op1
    call _op2set0                 ;0 -> op2
    call _cpop1op2              ;compare op1 and op2
    jr z, perf_sqr                  ;goto perf_sqr if the same
    ret                                ;return
                                          ;*********************
perf_sqr:
    call _zerooop1               ;0 -> op1
    call _op3toop1               ;op3 -> op1
    call _sqroot                      ;square root of op1 -> op1
    call _formdisp                ;Display op1
    ret                                ;return
prompt:
    .db "Number= ",0
.end
END


Thanks for any help,
   Ted


Follow-Ups: