[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: killing time in 6502 assembly
Paul Guertin said,
"Um, there is a better way. The following will take about 750000 cycles.
Fine-tuning the initial values of X and Y is left as an exercice for the
reader.
LDY #$AC
LDX #0
.1 JSR .2
DEX
BNE .1
DEY
BNE .1
.2 RTS
Challenge: can you come up with a shorter routine that waits for about
3/4 of a second?".
I can eliminate the LDX #$00.
LDY #$AD
L JSR R
DEX
BNE L
DEY
BNE L
R RTS
should take from 749260 to 753595 clock cycles, depending on the starting value
of X (max. for 0 and min. for 1).
Paul also said,
'It could be interesting to try to come up with 6502 "busy beavers".
A busy beaver is a program that eventually terminates (in other words,
it doesn't enter an infinite loop). The idea is to come up with the
program of length N that works for the longest time before terminating.
To preserve the theoretical flavor of the problem, assume 64k of RAM
and no ROM routines to call.'.
To try to preserve my remaining sanity, I didn't consier the case of 64
Kbytes of RAM. But I DID want to get a ballpark figure for the resulting time
interval, so I considered the case of 2314 bytes. The routine uses 2058 bytes:
LDA #$00
TAX
L STA $1000,X
INX
BNE L
00 INC $1000,X
JSR R
01 BNE 00
INC $1000,X
JSR R
02 BNE 01
INC $1000,X
JSR R
03 BNE 02
...
...
...
INC $1000,X
JSR R
FF BNE FE
INC $1000,X
JSR R
BNE FF
R RTS
Counting the page from $1000 to $10FF, a total of 2314 bytes are used. I
get 7.1E617 cycles. For a 1 MHz clock, that's about 2E602 centuries. I don't
know whether that's the best that can be done with 2314 bytes, and I CERTAINLY
don't know the answer to your question. A very intersting problem, Paul.
--
When backing up your hard drive, shift into reverse gear S M O O T H L Y.
John