Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (80 sloc) 3.33 KB
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title>Erasm++ - erasm</title>
<link rel="stylesheet" type="text/css" href="./css/default.css"></link>
<link rel="stylesheet" type="text/css" href="./css/syntax.css"></link>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29123087-1']);
_gaq.push(['_setDomainName', 'erasmpp.org']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="main">
<div id="sidebar">
<div id="header">
<h1>Erasm++ </h1>
</div>
<!-- <h2>Navigation</h2> -->
<a href="./">About</a>
<ul>
<li> <a href="./erasm.html">ERASM++</a> </li>
<li> <a href="./gendsm.html">GenericDsm</a> </li>
<li> <a href="./meta_prelude.html">MetaPrelude</a> </li>
</ul>
<a href="./download.html">Download/Install</a>
<a href="./manual/manual.html">Online Manual</a>
<a href="./privacy.html">Privacy Policy</a>
</div>
<div id="content">
<h1 id="erasm">Erasm++</h1>
<p>{sec:erasm++}</p>
<p>ERASM++, the Embedded Runtime Assembler in C++, is an Embedded Domain Specific Language (<a href="http://c2.com/cgi/wiki?EmbeddedDomainSpecificLanguage">EDSL</a>) in C++ for runtime code generation on Intel 64/IA-32 architectures. The code looks like the following:</p>
<pre><code>p += adc (p,word_ptr [edx + esi * _2],ax);
p += and_ (p,dword_ptr [rip + 0x1000],r12d);
p += rep_movs (p,dword_ptr.es [di],dword_ptr.gs [si]);
// Unfortunately, lables are not yet implemented!
p += jmp (p, 0x10);
</code></pre>
<p>Although similar runtime assembler libraries already exist, I believe ERASM++ has the following strengths:</p>
<ul>
<li><p>It is easier to use because the syntax is more natural.</p></li>
<li><p>It is safer to use because the syntactically invalid expressions cause compilation errors, rather than runtime errors or exceptions.</p></li>
<li><p>It is faster because most of the encoding and the error checking are done at compile-time, rather than at runtime.</p></li>
</ul>
<p>It’s so fast that each encoder function is actually compiled into a series of MOV instructions with no branches and no external references.</p>
<p>Here’s an example: g++ 4.6.1 compiles the following code</p>
<pre><code>extern &quot;C&quot; int code_test(code_ptr p)
{ return adc(p ,cl,byte_ptr [eax+ebp*_4+12345678]); }
</code></pre>
<p>to:</p>
<pre><code>[language={[x86masm]Assembler},frame=single]
_code_test:
sub esp, 32
mov eax, DWORD PTR [esp+36]
mov BYTE PTR [esp+5], -88
mov DWORD PTR [esp+6], 12345678
mov BYTE PTR [esp+4], -116
mov BYTE PTR [eax], 103
mov BYTE PTR [eax+1], 18
mov edx, DWORD PTR [esp+4]
mov DWORD PTR [eax+2], edx
mov edx, DWORD PTR [esp+8]
mov WORD PTR [eax+6], dx
mov eax, 8
add esp, 32
ret
</code></pre>
</div>
</dev>
</body>
</html>