Author Topic: z80 opcode usage stats  (Read 3930 times)

0 Members and 1 Guest are viewing this topic.

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
z80 opcode usage stats
« 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.
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: z80 opcode usage stats
« Reply #1 on: July 31, 2011, 11:55:13 am »
 :o O.O :o
And what can we learn from this pic?


looks funny!
*insert supercool signature*

SirCmpwn

  • Guest
Re: z80 opcode usage stats
« Reply #2 on: July 31, 2011, 12:22:35 pm »
Is there a key?  What do the colors represent?

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
Re: z80 opcode usage stats
« Reply #3 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.
« Last Edit: July 31, 2011, 12:45:42 pm by harold »
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: z80 opcode usage stats
« Reply #4 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?
« Last Edit: July 31, 2011, 12:58:46 pm by DJ_O »

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
Re: z80 opcode usage stats
« Reply #5 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?
« Last Edit: July 31, 2011, 02:04:54 pm by harold »
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: z80 opcode usage stats
« Reply #6 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
« Last Edit: July 31, 2011, 02:57:54 pm by ralphdspam »
ld a, 0
ld a, a