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

Re: A85: 16-bit integer Square Root (few changes)




I keep trying to take the square root of 54564 and each time I try to
display the answer the number254 is displayed.  Here's what the program
looks like, can anyone tell me what's wrong: (I made all of the changes
except pushing and popping hl)

#include "ti-85.h"

.org
.db "SQRT by Jarno Rajala",0

   ld hl,0
   ld (CURSOR_ROW),hl
   ld hl,54564
   CALL_(Sqrt16)
   ROM_CALL(D_HL_DECI)
KeyWait:
   call GET_KEY
   or a
   jr z, KeyWait
   ret
Sqrt16:
  push de
  push bc
  ld de, 0
  ld bc, 0
  call CP_HL_DE
  jr z, Sqrt16done  ;0 is a special case.
  ld de, 65280
  ld bc, 256
  sbc hl,de
  jr nc, Sqrt16done
  dec bc           ;bc=255
  rr l
  rr h         ;shift hl
  jr nc, noSet
  set 7, l
noSet:
  call Sqrt16loop
Sqrt16done:
  ld h, b
  ld l, c
  pop bc
  pop de
  ret
Sqrt16loop:
  add hl, bc
  ret c
  dec c
  jp Sqrt16loop
.end


Mordant
egillespie@juno.com
erik_gillespie_1096@gwgate.kvcc.edu

"Just because you're paranoid don't mean they're not after you." -Kurt
Cobain

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]


Follow-Ups: References: