The smallest test program ever!

9 posts / 0 new
Last post
Offline
Last seen: 1 year 1 month ago
Joined: Dec 10 2021 - 12:26
Posts: 33
The smallest test program ever!

This is something I and p-lab  came up when trying to write the smallest possible test program (the one the prints all the characters on the display).

Our version is only 6 bytes, here it is:

0000: E8 8A 20 EF FF 00

In 6502 assembly:

* = 0

INX

TXA

JSR ECHO

BRK

The trick here is to have a "BRK" instruction in place of "JMP $0" at the end of the program to close the loop.

BRK triggers an IRQ that on the Apple1 is mapped at address $0000, so it has the same effect of a JMP 0 but uses only one byte instead of three.

Offline
Last seen: 7 hours 17 min ago
Joined: Sep 21 2017 - 11:10
Posts: 38
Tiny test program

Very nice and clever!  I cobbled one together that was longer at 8 bytes but is relocatable to any valid address.  

 

0300: 18 8A 20 EF FF E8 90 F9

 

0300- 18          CLC

0301- 8A          TXA

0302- 20 EF FF    JSR  $FFEF

0305- E8          INX

0306- 90 F9       BCC  $0301

 

mmphosis's picture
Offline
Last seen: 1 month 3 days ago
Joined: Aug 18 2005 - 16:26
Posts: 442
I like it. Let me see how far

I like it. Let me see how far I can get...

FA:A2 FF 9A C8 98 60 EE FF F9 0

FAR

In 6502 assembly:

00FA-   A2 FF       LDX   #$FF

00FC-   9A          TXS

00FD-   C8          INY

00FE-   98          TYA

00FF-   60          RTS

0100- EE FF F9 00

In 10 bytes, not quite as small.

Offline
Last seen: 18 hours 26 min ago
Joined: Jun 25 2020 - 17:00
Posts: 251
No fair...

The smallest test program ever!

This is something I and p-lab  came up when trying to write the smallest possible test program (the one the prints all the characters on the display).

Our version is only 6 bytes, here it is:

0000: E8 8A 20 EF FF 00

In 6502 assembly:

* = 0

INX

TXA

JSR ECHO

BRK

 

You are not counting the JSR sub-routine and its RTS.

mmphosis's picture
Offline
Last seen: 1 month 3 days ago
Joined: Aug 18 2005 - 16:26
Posts: 442
Fair? How much more to bear

Fair? How much more to bear

 

BE6:8E 12 D0 E8 2C 12 D0 30 FB 10 F5

BEAR

 

In 6502 assembly:

 

0BE6- 8E 12 D0  STX $D012

0BE9- E8        INX

0BEA- 2C 12 D0  BIT $D012

0BED- 30 FB     BMI $0AF1

0BEF- 10 F5     BPL $0AF9

 

Self contained and relocatable in 11 bytes. Bloated!

I like nippur72's 6 byte version because it is less to remember and type:

 

0:E8 8A 20 EF FF 0

0R 

Offline
Last seen: 1 year 1 month ago
Joined: Dec 10 2021 - 12:26
Posts: 33
LaserMaster wrote:You are not
LaserMaster wrote:

You are not counting the JSR sub-routine and its RTS.

I am counting the number of bytes needed to type the program in the monitor, not the number of CPU instruction executed. 

Offline
Last seen: 6 months 3 weeks ago
Joined: Feb 18 2020 - 16:59
Posts: 46
Reminds me of the old "Name that Tune" :-)

Didn't know about the BRK on the Apple 1. A good test for an emulator to see how thorough the programmer was!

With that in mind, I suppose if you aren't too picky about what characters you see or the order in which they appear, you could type in a semi-useful test program using only four bytes:

 

00: 20 ED FF 00

 

Just a jump to two bytes before ECHO, which will add six to whatever's in A before falling through to ECHO.

I originally had written in this post that I thought it would eventually show either just the "odd" or just the "even" characters, depending on what A had it in when run. Forgive my massive post edit, because I later realized it was more complicated than that.

6 mod 255 is odd, so it would normally alternate odds/evens... but the carry flag will cause it to always add seven rather than six after you cross 255

In fact, if you run it with the R command, the A register will have 'R' in it and the carry flag will be initially set. So it will always start by displaying 'Y' (R + 7), and go from there.

  • Then it works its way up from Y (89 or $3B) through the upper odds, eventually getting to 251 ($FB)
  • The next ADC #6 gets you a wrap around to 1 and sets the carry flag.
  • The next ADC puts you at 8--an even number!
  • Now you'll hit evens all the way up:  14, 20, 26, 32... 248, 254, and then wrap around to 4.
  • But then the carry causes you to hit 11 next, and you're back on odds again:  17, 23, 29... and back to 89 (Y) again, where the whole thing starts over!

So the upshot is that you only wind up seeing about one-third of values 0-255. :-(

BUT... since the character set conveniently repeats several times, I think you still wind up getting every character displayed (anyone care to confirm that?), they're just not being displayed as a result of hitting every possible value.

 

 

Offline
Last seen: 1 day 2 hours ago
Joined: Apr 1 2020 - 16:46
Posts: 1002
The shorter this test program is, the better !

I think that these little minimalistic programming gems are very useful.

There is this nasty pitfall in the Apple-1 when the 3.5us oneshot pulse gets too long and gets near 3.9us, causing setup and hold time violations in the 6520 PIA (the 6820 seems to be more robust, but also must have the problem under some timing conditions).

So you want to measure the 3.5us pulse at pin #5 of the 74123 at location B-3.

But without any screen output going on you can't measure anything as there is no such pulse.

So this is when these little programs in this thread become useful.

The A1, A2 PROMs which come with my kits of course have a more sophisticated diagnostics page built in, no keyboard required, but enabling the diagnostics page involves bending pin #14 of each PROM a little bit, and this is not recommended more than twice, so only one activation and deactivation of the diagnostics page allowed.

These little programs can help to do the measurements without enabling (or having) the diagnostics page.

Very useful !

 

- Uncle Bernie

Offline
Last seen: 6 months 3 weeks ago
Joined: Feb 18 2020 - 16:59
Posts: 46
Now that I play around with it more...

From what I can tell, it looks like two characters are always skipped by my four-byte version. So, if you want all the characters, displayed due to hitting every 8-bit value, in order, the six-byte version still reigns as shortest.

If you're fine with just getting some of the 8-bit values, to display nearly (but not quite) all of the characters, in some order or another, then my four-byte version will fit the bill (and makes for a pretty darn good "test" if I do say so myself).

But what if you want a middle ground? All 8-bit values, generating all the characters, but you don't care about order? It turns out you can do it in five bytes:

 

00: 38 20 ED FF 00

 

SEC

JMP ECHO-2

BRK

 

Ensuring that the carry flag is always set will increment A by 7 each time, which will get it to hit every 8-bit value with equal frequency.

Log in or register to post comments