RosettaCodeData/Task/Machine-code/00DESCRIPTION

25 lines
813 B
Plaintext

The task requires poking machine code directly into memory and executing it.
This is strictly for x86 (32 bit) architectures.
The machine code is the opcodes of the following simple program:
<lang asm>mov EAX, [ESP+4]
add EAX, [ESP+8]
ret</lang>
which translates into the following opcodes:
(139 68 36 4 3 68 36 8 195)
and in Hex this would correspond to the following:
("8B" "44" "24" "4" "3" "44" "24" "8" "C3")
;Task:
Implement the following in your favorite programming language (take the common lisp code as an example if you wish):
<ol>
<li> Poke the above opcodes into a memory pointer</li>
<li>Execute it 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>
</ol>
<br><br>