Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from opcodes.x86_64 import read_instruction_set
import csv
import sys

# If "Opcodes" module is not installed, you can try running this example as:
# $ PYTHONPATH=`pwd` python ./examples/to_csv.py

# Print CSV document that contains each instruction form syntax
# with associated CPUID.

by_cpuid = {}

for inst in read_instruction_set():
for iform in inst.forms:
# Each isa_extensions element is of ISAExtension type.
cpuid = '+'.join(map(str, iform.isa_extensions))
row = (str(iform), cpuid)
if cpuid in by_cpuid:
by_cpuid[cpuid].append(row)
else:
by_cpuid[cpuid] = [row]

w = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
for cpuid in by_cpuid:
for row in by_cpuid[cpuid]:
w.writerow(row)
14 changes: 14 additions & 0 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ Installation

pip install --upgrade Opcodes

Quick start and examples
------------------------

.. code-block:: python

from opcodes.x86_64 import read_instruction_set

# Print each AMD64 instruction name and summary.
for inst in read_instruction_set():
# See "opcodes/x86_64.py" Instruction and InstructionForm classes.
print("{name}: {summary}".format(name=inst.name, summary=inst.summary))

See `examples <examples>`_ for more.

Users
-----

Expand Down