Skip to content

Commit 99cb83a

Browse files
authored
Update HOW-TO-USE.rst
Spell check and update information
1 parent 51e3cfa commit 99cb83a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

HOW-TO-USE.rst

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Introduction
2-
*************
2+
============
33

44
Welcome back to the wonderful times world of SEGV's (from the Python interpreter)!
55

@@ -30,7 +30,7 @@ instructions. Another reason why using ``pydisasm --xasm`` is
3030
preferable right now.
3131

3232
Format of assembly file
33-
-----------------------
33+
=======================
3434

3535
Again, easiest to consult the ``pydisasm --xasm`` output ``.pyasm``-file that is
3636
produced. Even easier, just to look in the test directory_ for files that end
@@ -45,7 +45,8 @@ determines which Python bytecode opcodes to use and which Python
4545
interpreter can be used to run the resulting program.
4646

4747
Module-level info
48-
-----------------
48+
------------------
49+
4950

5051
Here is an example of the module-level information:
5152

@@ -62,7 +63,7 @@ there is also a size modulo 2**32 that is recorded.
6263
# Source code size mod 2**32: 577 bytes
6364

6465
Method-level info
65-
.................
66+
------------------
6667

6768
Here is an example:
6869

@@ -111,7 +112,7 @@ So you could instead write:
111112

112113
LOAD_CONST (1)
113114

114-
which in this case does the same thing since `1 = constant[3]`. If the value 1 does not appear anywhere in the constants list, the assember would append the value 1 to the end of the list of the constants list. When writing the final bytecode file an appropriate constant index will be inserted into that instruction.
115+
which in this case does the same thing since `1 = constant[3]`. If the value 1 does not appear anywhere in the constants list, the assembler would append the value 1 to the end of the list of the constants list. When writing the final bytecode file an appropriate constant index will be inserted into that instruction.
115116

116117
Line Numbers and Labels
117118
-----------------------
@@ -151,7 +152,7 @@ Instructions
151152
-------------
152153

153154
The module level bytecode line determines what Python opcodes are
154-
exceptable and how operands are interpreted.
155+
acceptable and how operands are interpreted.
155156

156157
Instructions come after the other module or function information that starts with `#` and
157158
is shown above.
@@ -161,15 +162,16 @@ module field which would start with a #. And it is not a line number
161162
or label listed in the last section. We've seen examples of
162163
instructions above.
163164

164-
Opcodes
165-
+++++++
165+
Operation name
166+
...............
166167

167168
Instructions start with an opcode name like ``LOAD_CONST``. The specific opcode names used depends on the Python version you are using.
168169
So make sure to consult the "opcodes" section of the "dis" module documentation for the version of Python listed at the top of the metadata section.
169170

170171

171-
Operands
172-
++++++++
172+
Operand
173+
........
174+
173175

174176
An instruction may also have an operand depending
175177
on whether the opcode requires one or not. However as we've seen above,
@@ -192,6 +194,8 @@ parenthesis. For example:
192194

193195
Instructions can also have additional stuff after the operand and that is ignored.
194196

197+
Internally operand values are integers or indexes in some table. When an index value is more than 255 (the largest value that fits in a single byte), an ``EXTENDED_OPERAND`` instruction is added automatically.
198+
195199
Cool Stuff
196200
----------
197201

@@ -206,20 +210,9 @@ doesn't have to be the same as the Python interpreter that runs
206210
TODO
207211
-----
208212

209-
Possibly we should figure out when to put in ``EXTENDED_ARGS``
210-
instructions. And for now, even though you put in ``EXTENDED_ARGS``,
211-
the operand that follows may have the value folded into it. For
212-
example in Python 3.6 where an operand can be at most 255, of you
213-
wanted to jump relative 259 bytes you'd write:
214-
215-
::
216-
217-
EXTENDED_ARG 1 # Needed because below offset is greater than 255 away
218-
JUMP_FORWARD 259 # Should really be 3 (= 259 - 256)
219-
220213
We should have a better API to generate instructions from inside
221214
Python. This is pretty straightforward to do.
222215

223-
I've not put much in the way of error checking and error reporting.
216+
There is some error checking of consistency of the input file, but more error checking is desirable.
224217

225218
.. _directory: https://github.com/rocky/python-xasm/tree/master/test

0 commit comments

Comments
 (0)