Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Short answer:</strong> This function converts opcodes to string.</p> <p>The <code>*</code> IS RELATED to do with pointers! in fact, this function returns a <code>const char *</code> type. This is a pointer for a char buffer (in this case) used to point to a <a href="http://en.wikipedia.org/wiki/Null-terminated_string" rel="nofollow">C-String</a>. Every C-String is actually a buffer with "readable characteres" (alphanumerical, some accents, basic symbols + some stuff) followed by a byte of value 0 (or <code>'\0'</code>) to indicate the end of the string!</p> <p>This function converts opcodes (assembly instructions) to a readable string. So The intention of the programmer was to transform:</p> <ul> <li>0x01 -> OP_CODE1</li> <li>0x02 -> OP_CODE2</li> <li>0x03 -> OP_CODE3</li> </ul> <p>The expanded version of the code is something like this:</p> <pre><code>const char *getOpcodeName( uint8_t op ) { if((0x01)==op) return "OP_X"; if((0x02)==op) return "OP_Y"; if((0x03)==op) return "OP_Z"; ... if((0x??)==op) return "OP_?"; return "OP_UNKNOWN"; } </code></pre> <p>Insted of write houndreds of IF's ... the programmer decided to create the macro</p> <pre><code>#define OPCODE(x, y) if((0x##y)==op) return "OP_" #x; </code></pre> <p>So it's possible to write the OPCODES table easily like this:</p> <pre><code>#define OPCODES \ OPCODE( 01, "X" ) \ OPCODE( 02, "Y" ) \ OPCODE( 03, "Z" ) \ ... OPCODE( ??, "?" ) </code></pre> <p>Opcodes are codes that indentify the processor instruction (assembly instructions). Example of real instructions (for some <a href="http://sparksandflames.com/files/x86InstructionChart.html" rel="nofollow">Intel processor</a>) are:</p> <pre><code> inc eax ; opcode = 0x40 pusha ; opcode = 0x60 nop ; opcode = 0x90 </code></pre> <p>So your table could be:</p> <pre><code>#define OPCODES \ OPCODE( 40, "INCEAX" ) \ OPCODE( 60, "PUSHA" ) \ OPCODE( 90, "NOP" ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload