# Square root of an integer number

Page 5/5
1 | 2 | 3 | 4 |

now, who will do the code, an call it in a all the range and measure the time taken???'

the hard is to precalc the table....

then to compare with the time used using just the original routine, in the same all range of inputs.

and offcourse, to test that both outputs the same results.

is there a emulator that in debug mode, allows to count up used cycles? from a given breack point to another brackpoint?

How about this untested 8 bit version. I just drunk a lot of a beer so I cant tell if it is any good or faster even... either way it is definitly larger.

```; in hl
; out a = sqrt(hl)

sqrt
ld e,1

bit 6,h
jr nz,.large

inc h
ld a,l

.lus
sub e
inc e
inc e
jp nc,.lus

dec h
jp nz,.lus

ld a,e
rra
dec a
ret

.large
ld a,h
sub 63   ;-64+1
ld h,a

ld a,l

.lusl
sub e
inc e
inc e
jr c,.flow
dec h
jp nz,.lusl

jp .lexit

.flow
dec h
jr z,.lexit
dec h
jp nz,.lusl

.lexit
ld a,e
scf
rra
dec a
ret
```

is there a emulator that in debug mode, allows to count up used cycles? from a given breack point to another brackpoint?

It's already possible with openMSX: there is a command to get the current time in seconds (as a floating point number) since the MSX machine booted. Use this command twice, take the difference and multiply by the clockfrequency. So something like this:

```<breakpoint 1 hit>
>  set t1 [machine_info time]

<breakpoint 2 hit>
> set t2 [machine_info time]
> expr (\$t2 - \$t1) * 3579545
```

Or write a script to automate (part of) this.

How do you set a break point in openmsx ?
Can I import the a symbol table from an assembler ?
Hmmm...
How do you call the command line ?
:-)

```; in hl
; out a = sqrt(hl)

sqrt
ld e,1

ld a,h
sub 64
jr nc,.large

inc h
ld a,l

.lus
sub e
inc e
inc e
jp nc,.lus

dec h
jp nz,.lus

ld a,e
rra
dec a
ret

.large
ld h,a

inc h
ld a,l

.lusl
sub e
inc e
inc e
jr c,.flow
dec h
jp nz,.lusl

ld a,e
scf
rra
dec a
ret

.flow
dec h
jr z,.lexit
dec h
jp nz,.lusl

.lexit
ld a,e
scf
rra
dec a
ret
```

How do you set a break point in openmsx ?

See: http://openmsx.sourceforge.net/manual/commands.html#debug
use the subcommand set_bp

Can I import the a symbol table from an assembler ?

Using the graphical gui for the debugger, you can. A snapshot can be downloaded from our web site: http://openmsx.sourceforge.net/temp/openmsx-debugger-win32-bin-snapshot.zip

You can also set breakpoints with that debugger of course.

Hmmm...
How do you call the command line ?
:-)