Machine code: Difference between revisions

Task description: Already there are some examples that do not strictly follow the x86 32-bit rule of this task. Relaxed requirements... Hopefully this encourages more contributions for other systems. Also cleaned up some formatting.
(→‎{{header|Lua}}: added Lua non-solution)
(Task description: Already there are some examples that do not strictly follow the x86 32-bit rule of this task. Relaxed requirements... Hopefully this encourages more contributions for other systems. Also cleaned up some formatting.)
Line 1:
{{task}}
The task requires poking machine code directly into memory and executing it. The machine code is the architecture-specific opcodes which has the simple task of adding two unsigned bytes together and making the result available to the high-level language.
 
ThisFor example, the following assembly language program is strictlygiven for x86 (32 bit) architectures. :
 
The machine code is the opcodes of the following simple program:
 
<lang asm>mov EAX, [ESP+4]
Line 10 ⟶ 8:
ret</lang>
 
whichThis translateswould translate into the following opcodesopcode bytes:
(<lang>139 68 36 4 3 68 36 8 195)</lang>
and in Hex this would correspond to the following:
("8B" "44" "24" "4" "3" "44" "24" "8" "C3")
 
Or in hexadecimal:
<lang>8B 44 24 04 03 44 24 08 C3</lang>
 
;Task:
If different than 32-bit x86, specify the target architecture of the machine code for your example. It may be helpful to also include an assembly version of the machine code for others to reference and understand what is being executed. Then, implement the following in your favorite programming language:
Implement the following in your favorite programming language (take the common lisp code as an example if you wish):
 
<ol>
<li>* Poke the abovenecessary opcodes into a memory pointer</li>location.
* Provide a means to pass two values to the machine code.
<li>* Execute itthe machine code with the following arguments: [ESP+4] => unsigned-byte argument of value 7; [ESP+8] => unsigned-byte argument of value 12; The result would be 19.</li>
<li>Free the Pointer</li>
* Perform any clean up actions that are appropriate for your chosen language (free the pointer or memory allocations, etc.)
</ol>
 
<br><br>
 
=={{header|AutoHotkey}}==
113

edits