Omnimaga

Calculator Community => Other Calculators => Topic started by: harold on July 31, 2011, 09:49:28 am

Title: z80 opcode usage stats
Post by: harold on July 31, 2011, 09:49:28 am
I did a primitive order-1 frequency analysis of z80 opcodes as used in TIOS.
It's pretty useless really, but it shows some interesting things.
For example, it's clear that control flow instructions are particularly popular.
Also, there's a general bias towards low values. This bias is much higher for immediate values (as in ld a,imm8 and cp imm8)
Perhaps something to keep in mind when writing a compressor for programs.
Title: Re: z80 opcode usage stats
Post by: p2 on July 31, 2011, 11:55:13 am
 :o O.O :o
And what can we learn from this pic?


looks funny!
Title: Re: z80 opcode usage stats
Post by: SirCmpwn on July 31, 2011, 12:22:35 pm
Is there a key?  What do the colors represent?
Title: Re: z80 opcode usage stats
Post by: harold on July 31, 2011, 12:43:59 pm
Hotter colours are more common.
In order, black, gray, green, yellow, red, purple

One of the things I noticed is that the ED prefix isn't rare in itself, but doesn't have one of those "lines" across the map - it's only common in combination with a few select bytes following it.
Title: Re: z80 opcode usage stats
Post by: DJ Omnimaga on July 31, 2011, 12:58:13 pm
Interesting Harold. :) One thing to keep in mind, however, is that TI apparently hardly optimized their OS code (judging by the reactions from BrandonW while he was examinating the code during a video livestream last year), so I wouldn't be surprised if the average ASM source by people on this forum gave different results. :P

By the way how did you generate this pic?
Title: Re: z80 opcode usage stats
Post by: harold on July 31, 2011, 01:22:52 pm
I wrote a small C# program, barely a dozen lines of code..
Then I took a look at it and marked some lines.

My guess is that optimized assembly has a higher arithmetic/control-flow ratio (and also less cp's, by using the flags from other instructions better), but I couldn't quickly gather enough proper material to analyze.


In the upper left part of the lower right quadrant (so, just off the middle), there are a couple of intriguing diagonal lines - does anyone have any thoughts on that?
Title: Re: z80 opcode usage stats
Post by: ralphdspam on July 31, 2011, 02:37:59 pm
Lol, look at the NOPs at the top.
I thought TI's most common instruction was ld a,a.  :P