Difference between revisions of "General Coding Tricks"
From SizeCoding
(Created page with "== Jumping into the middle of instructions ==") |
(→Jumping into the middle of instructions) |
||
Line 1: | Line 1: | ||
− | == | + | == Data is code, code is data == |
+ | |||
+ | Code is nothing more than data that the CPU interprets. For example, consider this multi-byte instruction: | ||
+ | |||
+ | <syntaxhighlight lang=nasm> | ||
+ | mov ah,37h | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | This assembles to <code>B4 37</code>. <code>B4</code> by itself isn't interesting, but <code>37</code> is the opcode for <code>AAS</code>. Let's say you had this code before a loop, and you needed to perform <code>AAS</code> at the top of a loop. Rather than put AAS at the top of the loop, you can reuse the opcode that will already be there as part of the <code>mov ah,37</code> that comes before it. Just jump directly into the middle of the <code>mov ah,37h</code>, which will get interpreted and executed as <code>AAS</code>: | ||
+ | |||
+ | <syntaxhighlight lang=nasm> | ||
+ | |||
+ | label: | ||
+ | mov ah,37h | ||
+ | ;misc. stuff | ||
+ | loop label+1 | ||
+ | </syntaxhighlight> |
Revision as of 15:33, 6 August 2016
Data is code, code is data
Code is nothing more than data that the CPU interprets. For example, consider this multi-byte instruction:
mov ah,37h
This assembles to B4 37
. B4
by itself isn't interesting, but 37
is the opcode for AAS
. Let's say you had this code before a loop, and you needed to perform AAS
at the top of a loop. Rather than put AAS at the top of the loop, you can reuse the opcode that will already be there as part of the mov ah,37
that comes before it. Just jump directly into the middle of the mov ah,37h
, which will get interpreted and executed as AAS
:
label:
mov ah,37h
;misc. stuff
loop label+1