<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>What is a TOKEN (C++)</title>
		<link>http://www.allegro.cc/forums/view/588646</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 23 Nov 2006 05:02:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not beyond asking for help especially when my professor is a real tool.</p><p>this is my homework assignment</p><p>( 20 points ) We discussed in class converting an infix expression to a postfix expression. In the implementation of in2post.cpp, we have used an operator stack to hold the operators and both the inputs and outputs are strings; it can only handle integers. You may generalize it by passing in the infix expression in a stack and output the postfix expression in a queue. You may define a TOKEN which can be an operator or a number as follows:</p><p>	enum WhatKind { oper, number };<br />	typedef struct {<br />	  WhatKind	kind;<br />	  double	num;<br />	  char		op;<br />	} TOKEN;</p><p>Your conversion function may have the form,<br />void in2post( stack &lt;TOKEN&gt; &amp;infix, queue &lt;TOKEN&gt; &amp;postqueue );</p><p>Before calling this function, you have to parse the infix expression into TOKENs and put them in the infix stack. The output is the postfix tokens saved in postqueue.</p><p>Next, write a function to evaluate the postfix expression. You may first convert the postfix queue to the post stack. Your function may look like:</p><p>	double evaluate ( stack &lt;TOKEN&gt; &amp;post )<br />	{<br />	  stack  eval;<br />	  double first, second, ans;<br />	  char bin_op;<br />	  TOKEN tp, te;<br />	  while ( !post.empty() ){<br />	    tp = post.top();<br />	    post.pop();<br />	    if ( tp.kind == number )<br />		eval.push( tp );<br />	    else {<br />		...<br />	    }<br />	  }<br />	  ....<br />	}    </p><p>What&#39;s a TOKEN?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relay01)</author>
		<pubDate>Tue, 21 Nov 2006 01:58:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
...</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">typedef</span> <span class="k1">struct</span> <span class="k2">{</span>
WhatKind kind<span class="k2">;</span>
<span class="k1">double</span> num<span class="k2">;</span>
<span class="k1">char</span> op<span class="k2">;</span>
<span class="k2">}</span> TOKEN<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Tue, 21 Nov 2006 02:02:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See <a href="http://en.wikipedia.org/wiki/Token_%28parser%29">here</a> <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Tue, 21 Nov 2006 02:28:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>aah... i still don&#39;t get it... what are &quot;lexemes&quot;?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relay01)</author>
		<pubDate>Tue, 21 Nov 2006 02:48:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Eris on a freaking pogo stick, <a href="http://en.wikipedia.org/wiki/Lexeme">just use the damn wikipedia</a>. Just <i>try it.</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Tue, 21 Nov 2006 02:54:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /> ok
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relay01)</author>
		<pubDate>Tue, 21 Nov 2006 03:47:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You suck relay01! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 04:14:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Given the lack of code tags, I would have to agree with that statement.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 21 Nov 2006 04:42:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sheesh, I had to do that in MIPS assembler, and here you get to use a nice high level language.  What are you complaining about?</p><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
especially when my professor is a real tool.
</p></div></div><p>

Yeah, because he did half the work for you.... <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Tue, 21 Nov 2006 07:41:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>relay01,</p><p>I don&#39;t know if your question was answered or not.</p><p>I believe your professor means that TOKEN should be one of the math functions.<br /><span class="source-code">   A <span class="k3">*</span> B <span class="k3">-</span> C <span class="k3">/</span> <span class="k2">(</span>D <span class="k3">+</span> E<span class="k2">)</span></span></p><p>Each of the MULTIPLY, DIVIDE, ADD, SUBTRACT are the &quot;TOKENS&quot; to which your professor is referring.</p><p>You should probably have two strings: <tt>infixString</tt> and <tt>postfixString</tt>.</p><p>Basically:</p><p>1) You are given an INFIX problem (like above)<br />2) Parse the INFIX expression, and print out the resulting POSTFIX expression<br />- i) For each character that is read in from the <tt>infixString</tt>, perform the following:<br />- ii) If the input character is a letter, append that letter to the end of <tt>postfixString</tt><br />- iii) If the input character is a TOKEN, put that TOKEN onto a stack which you will retrieve later<br />- iv) If the next input character is another letter, get (read: POP) the TOP element from your stack and insert it onto the end of your <tt>postfixString</tt>.<br />- v) You have to make sure to check the preference of the TOKENS when you remove them: <b>*</b>, <b>/</b> and <b>%</b> have higher precedence than <b>+</b> or <b>-</b>, so be sure to remove the correct one.<br />3) Output, at the very end, the POSTFIX string</p><p>The only exception to the above is if your professor&#39;s code includes parentheses (like in my example INFIX expression).  If he does, once you encounter a <b>)</b>, you have to loop though all the items in your stack until you find the <b>(</b> and push everything you find into your <tt>postfixString</tt>.</p><p>This way, the above will do this:<br /><span class="source-code">   A <span class="k3">*</span> B <span class="k3">-</span> C <span class="k3">/</span> <span class="k2">(</span>D <span class="k3">+</span> E<span class="k2">)</span></span></p><pre>
infixString          postfixString                  myStack
-----------          -------------                  -------
A                    A                              (empty)
*                                                   *
B                    AB*                            (empty) -- (because we removed the &quot;*&quot;)
-                    AB*                            -
C                    AB*C                           - (not removed because the NEXT character is higher-precedence: &quot;/&quot;)
/                    AB*C                           -/
(                    AB*C                           -/(
D                    AB*CD                          -/(
+                    AB*CD                          -/(+
E                    AB*CDE+                        -/( (removed the &quot;+&quot;)
)                    AB*CDE+                        -/ (removed the &quot;(&quot;)
                     AB*CDE+/                       - (still inside the FOR..LOOP for the &quot;)&quot; TOKEN)
                     AB*CDE+/-                      (empty)
</pre><p>

I hope that helps somewhat with your assignment.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeamTerradactyl)</author>
		<pubDate>Tue, 21 Nov 2006 08:14:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Sheesh, I had to do that in MIPS assembler, and here you get to use a nice high level language. What are you complaining about?
</p></div></div><p>
Well if you are learning compiler theory then I would argue that it&#39;s better to stay high level. You&#39;ll get more done faster and learn more about the stuff you are supposed to study (compiler theory, not assembler).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 08:34:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not if he also had to actually compile to machine code <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> Knowing the assembler would go a long way to understanding the workings of the chip/system, and what to compile the code to <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 Nov 2006 20:08:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah but technically that&#39;s not compiler theory. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 21:07:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Um, compiling code isn&#39;t compiler theory? Whod&#39;a thunk it!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 Nov 2006 22:20:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Assembler isn&#39;t compiler theory. If it was then you could say that any format is compiler theory, as it&#39;s necessary knowledge if you want to compile something into said format (PostScript, PDF, SVG, XML, HTML and so on). Compiler theory in itself are the generic methods used to turn one format into another.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 22:51:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you need to read what I said again <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p><div class="quote_container"><div class="title">I said:</div><div class="quote"><p>
Knowing the assembler would go a long way to understanding the workings of the chip/system, and what to compile the code to <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div></div><p>

That last message I was pulling your chain <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 Nov 2006 23:13:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah he needs to know assembler in that case. Can&#39;t really get why he head to implement his compiler in assembler though, but I guess it could be a good exercise if you study assembler.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 23:29:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe hes just old? <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />  IIRC his day job involves a lot of COBOL. (at least I think its him..)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 Nov 2006 23:42:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Writing an assembler is obviously a compiler theory thing. A compiler is a compiler no matter what it compiles. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Tue, 21 Nov 2006 23:42:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think hes saying writing it IN assembler isn&#39;t so much compiler theory, and may get in the way of teaching pure compiler theory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 Nov 2006 23:43:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, compiler theory is just that, theory: It&#39;s got nothing to do with whatever language you&#39;re using should you want to actually write a compiler.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Tue, 21 Nov 2006 23:59:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, that&#39;s what I&#39;m saying Thomas. I haven&#39;t said that writing an assembler isn&#39;t a compiler theory thing, at least I don&#39;t think so? I&#39;ve said that learning assembler isn&#39;t a compiler theory thing and that you would probably want to use a high level language if you want to create a compiler. As you will get more stuff done and have a greater freedom to experiment.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Tue, 21 Nov 2006 23:59:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When I started with assembler, <i>I</i> was the assembler. I wrote the assembler code with pencil on paper. Then, using a table, I looked up the hexcodes and wrote them down on the same paper next to the assembler mnemonics. Then I had to count the bytes to get all absolute and relative jumps right. Then I typed in the hexcode.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Wed, 22 Nov 2006 00:08:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I couldn&#39;t stand the thought of having to do that for my two VM projects, so I ended up writing some nice assemblers for both of them <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> first one was two pass, so you could actually reference labels that are declared after you use them <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 00:13:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s some crazy stuff Johan. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> When was that?</p><p>Sounds cool Thomas. Tell us more about them? Perhaps show some of that assembler code? <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Wed, 22 Nov 2006 00:19:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I must tell you, the first VM i did was one of my first real projects, back almost 6 years ago. The code has been worked on at various times over the years, so its kinda messy and not well thought out.</p><p>casminfo.txt:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">/*</span></td></tr><tr><td class="number">2</td><td><span class="c">CHIP and Casm INFO.</span></td></tr><tr><td class="number">3</td><td><span class="c">-</span></td></tr><tr><td class="number">4</td><td><span class="c"></span></td></tr><tr><td class="number">5</td><td><span class="c">Instruction Information:</span></td></tr><tr><td class="number">6</td><td><span class="c"></span></td></tr><tr><td class="number">7</td><td><span class="c">Ins    Args       Desc</span></td></tr><tr><td class="number">8</td><td><span class="c">----------------------</span></td></tr><tr><td class="number">9</td><td><span class="c">NOOP   0          Does nothing.</span></td></tr><tr><td class="number">10</td><td><span class="c">MUL    2          8bit Multiply arg2 with arg1 (arg1 *= arg2)</span></td></tr><tr><td class="number">11</td><td><span class="c">DIV    2          8bit Divide arg2 with arg1   (arg1 /= arg2)</span></td></tr><tr><td class="number">12</td><td><span class="c">MOD    2          8bit Modulo arg2 with arg1   (arg1 %= arg2)</span></td></tr><tr><td class="number">13</td><td><span class="c">ADD    2          8bit Add arg2 with arg1      (arg1 += arg2)</span></td></tr><tr><td class="number">14</td><td><span class="c">SUB    2          8bit Subtract arg2 with arg1 (arg1 -= arg2)</span></td></tr><tr><td class="number">15</td><td><span class="c">MOV    2          8bit Copy arg2 to arg1</span></td></tr><tr><td class="number">16</td><td><span class="c">PUT    1          Puts a character to stdout. (non buffered)</span></td></tr><tr><td class="number">17</td><td><span class="c">GET    1          Gets a character from stdin (non buffered, noecho)</span></td></tr><tr><td class="number">18</td><td><span class="c">OR     2          8bit bitwise OR ( | )</span></td></tr><tr><td class="number">19</td><td><span class="c">XOR    2          8bit bitwise XOR ( ^ )</span></td></tr><tr><td class="number">20</td><td><span class="c">AND    2          8bit bitwise AND ( &amp; )</span></td></tr><tr><td class="number">21</td><td><span class="c">POP    1          Pops a value off the stack to arg</span></td></tr><tr><td class="number">22</td><td><span class="c">POP0   0          Pops a value off the stack and forgets it (same as DEC SP)</span></td></tr><tr><td class="number">23</td><td><span class="c">PUSH   1          Pushes a value to the stack</span></td></tr><tr><td class="number">24</td><td><span class="c">MULL   2          32bit Multiply arg2 with arg1 (arg1 *= arg2)</span></td></tr><tr><td class="number">25</td><td><span class="c">DIVL   2          32bit Divide arg2 with arg1   (arg1 /= arg2)</span></td></tr><tr><td class="number">26</td><td><span class="c">MODL   2          32bit Modulo arg2 with arg1   (arg1 %= arg2)</span></td></tr><tr><td class="number">27</td><td><span class="c">ADDL   2          32bit Add arg2 with arg1      (arg1 += arg2)</span></td></tr><tr><td class="number">28</td><td><span class="c">SUBL   2          32bit Subtract arg2 with arg1 (arg1 -= arg2)</span></td></tr><tr><td class="number">29</td><td><span class="c">INC    1          Increment arg (++arg)</span></td></tr><tr><td class="number">30</td><td><span class="c">DEC    1          Deincrement arg (--arg)</span></td></tr><tr><td class="number">31</td><td><span class="c">DUMP   0          Dumps the register values to stdout</span></td></tr><tr><td class="number">32</td><td><span class="c">MOVL   2          32bit Copy arg2 to arg1</span></td></tr><tr><td class="number">33</td><td><span class="c">JMP    1          Unconditional jump to arg</span></td></tr><tr><td class="number">34</td><td><span class="c">CMP    2          Compare arg1 to arg2</span></td></tr><tr><td class="number">35</td><td><span class="c">JE     1          Jump to arg if last CMP result was equal</span></td></tr><tr><td class="number">36</td><td><span class="c">JNE    1          Jump to arg if last CMP result was not equal</span></td></tr><tr><td class="number">37</td><td><span class="c">JL     1          Jump to arg if last CMP result was less than</span></td></tr><tr><td class="number">38</td><td><span class="c">JLE    1          Jump to arg if last CMP result was less than or equal</span></td></tr><tr><td class="number">39</td><td><span class="c">JG     1          Jump to arg if last CMP result was greater than</span></td></tr><tr><td class="number">40</td><td><span class="c">JG     1          Jump to arg if last CMP result was greater than or equal</span></td></tr><tr><td class="number">41</td><td><span class="c">LOOP   2          Loop to arg for times specified in register C</span></td></tr><tr><td class="number">42</td><td><span class="c">CALL*  1          Call 'function' arg.</span></td></tr><tr><td class="number">43</td><td><span class="c">RET*   1          Return from a 'function' and push arg to stack</span></td></tr><tr><td class="number">44</td><td><span class="c">HLT    0          Stops CHIP.</span></td></tr><tr><td class="number">45</td><td><span class="c">ORL    2          32bit bitwise OR ( | )</span></td></tr><tr><td class="number">46</td><td><span class="c">XORL   2          32bit bitwise XOR ( ^ )</span></td></tr><tr><td class="number">47</td><td><span class="c">ANDL   2          32bit bitwise AND ( &amp; )</span></td></tr><tr><td class="number">48</td><td><span class="c">SHR    1          Bitwise right shift ( &gt;&gt; )</span></td></tr><tr><td class="number">49</td><td><span class="c">SHL    1          Bitwise left shift ( &lt;&lt; )</span></td></tr><tr><td class="number">50</td><td><span class="c">XCHG   2          Exchanges the values of it's two arguments</span></td></tr><tr><td class="number">51</td><td><span class="c">LOR    2          Logical OR  ( || )</span></td></tr><tr><td class="number">52</td><td><span class="c">LAND   2          Logical AND ( &amp;&amp; )</span></td></tr><tr><td class="number">53</td><td><span class="c">INT*   1          Calls CHIP's 'BIOS' function 'arg' (returns nothing)</span></td></tr><tr><td class="number">54</td><td><span class="c">CALLEX* 1         Calls CHIP's 'BIOS' function 'arg' (returns int)</span></td></tr><tr><td class="number">55</td><td><span class="c"></span></td></tr><tr><td class="number">56</td><td><span class="c"></span></td></tr><tr><td class="number">57</td><td><span class="c">Aditional Instruction Information:</span></td></tr><tr><td class="number">58</td><td><span class="c">----------------------------------</span></td></tr><tr><td class="number">59</td><td><span class="c">CALL is almost like JMP except that all the registers</span></td></tr><tr><td class="number">60</td><td><span class="c">are pushed on to the stack and arguments pushed onto</span></td></tr><tr><td class="number">61</td><td><span class="c">the stack before CALL are available in reverse order</span></td></tr><tr><td class="number">62</td><td><span class="c">using a '$' followed by a number, so arg $1 is the last</span></td></tr><tr><td class="number">63</td><td><span class="c">argument that was pushed onto the stack.</span></td></tr><tr><td class="number">64</td><td><span class="c">Also the CALLer is responsible for removing arguments</span></td></tr><tr><td class="number">65</td><td><span class="c">it provided to the CALLed 'function'.</span></td></tr><tr><td class="number">66</td><td><span class="c"></span></td></tr><tr><td class="number">67</td><td><span class="c">All CALLed 'functions' must use RET to restore</span></td></tr><tr><td class="number">68</td><td><span class="c">the original register values.</span></td></tr><tr><td class="number">69</td><td><span class="c">After a 'function' RETurns it's return value</span></td></tr><tr><td class="number">70</td><td><span class="c">is placed in the special purpose R register.</span></td></tr><tr><td class="number">71</td><td><span class="c"></span></td></tr><tr><td class="number">72</td><td><span class="c">INT is basically a hack to easily add instructions</span></td></tr><tr><td class="number">73</td><td><span class="c">that don't need to be added directly to CHIP.</span></td></tr><tr><td class="number">74</td><td><span class="c">These extra 'instructions' are added by the program</span></td></tr><tr><td class="number">75</td><td><span class="c">that is using CHIP, i.e: [out|in]portb functionality</span></td></tr><tr><td class="number">76</td><td><span class="c">or setting SIG* callbacks.</span></td></tr><tr><td class="number">77</td><td><span class="c"></span></td></tr><tr><td class="number">78</td><td><span class="c">Register information:</span></td></tr><tr><td class="number">79</td><td><span class="c">---------------------</span></td></tr><tr><td class="number">80</td><td><span class="c">There are 36 general registers %AA through %FF,</span></td></tr><tr><td class="number">81</td><td><span class="c">one StackPointer (SP) register, and as mentioned</span></td></tr><tr><td class="number">82</td><td><span class="c">above, a RETurn value register.</span></td></tr><tr><td class="number">83</td><td><span class="c">You must prefix all the general registers with %,</span></td></tr><tr><td class="number">84</td><td><span class="c">the SP and R register can be preixed by % but it is not required.</span></td></tr><tr><td class="number">85</td><td><span class="c">The first 6 registers can be abriviated as %A through %F</span></td></tr><tr><td class="number">86</td><td><span class="c"></span></td></tr><tr><td class="number">87</td><td><span class="c">All registers can be preceded by MEM or ST (including SP and R :),</span></td></tr><tr><td class="number">88</td><td><span class="c">which refrences the value in the register to</span></td></tr><tr><td class="number">89</td><td><span class="c">a memory address or stack address in that order.</span></td></tr><tr><td class="number">90</td><td><span class="c">(you get the value at the memory/stack addr)</span></td></tr><tr><td class="number">91</td><td><span class="c"></span></td></tr><tr><td class="number">92</td><td><span class="c">Also all general registers can be signed or unsigned and</span></td></tr><tr><td class="number">93</td><td><span class="c">bisected into thier individual 'words' (16 bits un/signed)</span></td></tr><tr><td class="number">94</td><td><span class="c">and those can be bisected into thier individual bytes</span></td></tr><tr><td class="number">95</td><td><span class="c">(8 bits un/signed).</span></td></tr><tr><td class="number">96</td><td><span class="c"></span></td></tr><tr><td class="number">97</td><td><span class="c">The format for registers is:</span></td></tr><tr><td class="number">98</td><td><span class="c">%AA (short form for signed long int register 0, or just %A)</span></td></tr><tr><td class="number">99</td><td><span class="c">%AAUW1 (for unsigned high word of register 0, or just %AUW1)</span></td></tr><tr><td class="number">100</td><td><span class="c">%AAUW0 (for same as above but low word.)</span></td></tr><tr><td class="number">101</td><td><span class="c">%AAUB0 (for unsigned 'first' byte of the register)</span></td></tr><tr><td class="number">102</td><td><span class="c">etc...</span></td></tr><tr><td class="number">103</td><td><span class="c">Replace the 'U' with a 'S' for the signed variants.</span></td></tr><tr><td class="number">104</td><td><span class="c">Also you can use an 'I' to use the register as</span></td></tr><tr><td class="number">105</td><td><span class="c">a 32bit wide value, but it is not required as that</span></td></tr><tr><td class="number">106</td><td><span class="c">is the default.</span></td></tr><tr><td class="number">107</td><td><span class="c"></span></td></tr><tr><td class="number">108</td><td><span class="c">Instruction Parameters:</span></td></tr><tr><td class="number">109</td><td><span class="c">-----------------------</span></td></tr><tr><td class="number">110</td><td><span class="c">Generally registers, memory addresses, '$' args, and</span></td></tr><tr><td class="number">111</td><td><span class="c">literal integers can be used as a parameter to any</span></td></tr><tr><td class="number">112</td><td><span class="c">instruction, with these exceptions:</span></td></tr><tr><td class="number">113</td><td><span class="c"> 1. A parameter can not be a literal integer if that parameter</span></td></tr><tr><td class="number">114</td><td><span class="c">    gets modified by the instruction.</span></td></tr><tr><td class="number">115</td><td><span class="c"> 2. The second parameter for DIV DIVL MOD and MODL can not be</span></td></tr><tr><td class="number">116</td><td><span class="c">    less than 1. (impossible when using an 'unsigned' register)</span></td></tr><tr><td class="number">117</td><td><span class="c"></span></td></tr><tr><td class="number">118</td><td><span class="c">All parameters can be preceded by MEM or ST,</span></td></tr><tr><td class="number">119</td><td><span class="c">which refrences the value to a memory address</span></td></tr><tr><td class="number">120</td><td><span class="c">or stack address in that order.</span></td></tr><tr><td class="number">121</td><td><span class="c">(you get the value at the memory/stack addr)</span></td></tr><tr><td class="number">122</td><td><span class="c"></span></td></tr><tr><td class="number">123</td><td><span class="c">Additional Casm information:</span></td></tr><tr><td class="number">124</td><td><span class="c">----------------------------</span></td></tr><tr><td class="number">125</td><td><span class="c">The Chip Assembler is Case insesitive, so</span></td></tr><tr><td class="number">126</td><td><span class="c">ADD is the same as AdD.</span></td></tr><tr><td class="number">127</td><td><span class="c">Also the CHIP Assembler includes lables (case sensitive)</span></td></tr><tr><td class="number">128</td><td><span class="c">which are Identical to other assembler's labels, and</span></td></tr><tr><td class="number">129</td><td><span class="c">the psuedo instruction DB which stores the folowing string,</span></td></tr><tr><td class="number">130</td><td><span class="c">and DW which stores the following integer at the current</span></td></tr><tr><td class="number">131</td><td><span class="c">position in the compiled CHIP machine code.</span></td></tr><tr><td class="number">132</td><td><span class="c">It is recomended that you precede the DB and DW psuedo</span></td></tr><tr><td class="number">133</td><td><span class="c">ops with a lable so the address of the data is</span></td></tr><tr><td class="number">134</td><td><span class="c">easily avaliable.</span></td></tr><tr><td class="number">135</td><td><span class="c">*/</span></td></tr></tbody></table></div></div><p>

The actual code for the assembler is attached (comp.c), I assume it won&#39;t fi tin a code box, even with much of the unnesesary bits pulled out.</p><p>Also attached (parse.c) is the assembler for my newer script vm.</p><p>edit:</p><p>Heres an example asm file for the parse.c assembler:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>set rand.low <span class="n">1</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="p"># set starting 'x' pos of thing</span></td></tr><tr><td class="number">4</td><td>set rand.seed screen.width</td></tr><tr><td class="number">5</td><td>set rand.high screen.width</td></tr><tr><td class="number">6</td><td>set thing.x rand.ival</td></tr><tr><td class="number">7</td><td>&#160;</td></tr><tr><td class="number">8</td><td><span class="p"># set starting 'y' pos of thing</span></td></tr><tr><td class="number">9</td><td>set rand.seed screen.height</td></tr><tr><td class="number">10</td><td>set rand.high screen.height</td></tr><tr><td class="number">11</td><td>set thing.y rand.ival</td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td>set rand.seed time.abs</td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td><span class="p"># start loop</span></td></tr><tr><td class="number">16</td><td>label loop</td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td><span class="p"># angle</span></td></tr><tr><td class="number">19</td><td>set thing.ax mouse.x</td></tr><tr><td class="number">20</td><td>sub thing.ax thing.x</td></tr><tr><td class="number">21</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a> thing.ax thing.ax</td></tr><tr><td class="number">22</td><td>&#160;</td></tr><tr><td class="number">23</td><td>set thing.ay mouse.y</td></tr><tr><td class="number">24</td><td>sub thing.ay thing.y</td></tr><tr><td class="number">25</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a> thing.ay thing.ay</td></tr><tr><td class="number">26</td><td>&#160;</td></tr><tr><td class="number">27</td><td>set thing.c thing.ax</td></tr><tr><td class="number">28</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_618.html" target="_blank">pow</a> thing.c <span class="n">2</span></td></tr><tr><td class="number">29</td><td>&#160;</td></tr><tr><td class="number">30</td><td>set thing.d thing.ay</td></tr><tr><td class="number">31</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_618.html" target="_blank">pow</a> thing.d <span class="n">2</span></td></tr><tr><td class="number">32</td><td>&#160;</td></tr><tr><td class="number">33</td><td>&#160;</td></tr><tr><td class="number">34</td><td>&#160;</td></tr><tr><td class="number">35</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_134.html" target="_blank">div</a> thing.ax thing.ay</td></tr><tr><td class="number">36</td><td>&#160;</td></tr><tr><td class="number">37</td><td>cot thing.angle thing.ax</td></tr><tr><td class="number">38</td><td>&#160;</td></tr><tr><td class="number">39</td><td><span class="p"># deltas</span></td></tr><tr><td class="number">40</td><td>&#160;</td></tr><tr><td class="number">41</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a> thing.dx thing.angle</td></tr><tr><td class="number">42</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_728.html" target="_blank">sin</a> thing.dy thing.angle</td></tr><tr><td class="number">43</td><td>&#160;</td></tr><tr><td class="number">44</td><td><span class="p"># new position</span></td></tr><tr><td class="number">45</td><td>&#160;</td></tr><tr><td class="number">46</td><td>sub thing.x thing.dx</td></tr><tr><td class="number">47</td><td>add thing.y thing.dy</td></tr><tr><td class="number">48</td><td>&#160;</td></tr><tr><td class="number">49</td><td>jmp loop</td></tr><tr><td class="number">50</td><td><span class="p"># Dude!</span></td></tr></tbody></table></div></div><p>
This one utilized the allegro binding I made for it. screen is allegro&#39;s screen, and &quot;thing&quot; is an object that the program used to draw a box or pixle on screen.</p><p>And heres an example for he comp.c assembler:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>include <span class="s">"lib.inc"</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td>ENTRY</td></tr><tr><td class="number">4</td><td>   push <span class="n">33</span></td></tr><tr><td class="number">5</td><td>   call fib</td></tr><tr><td class="number">6</td><td>   put <span class="s">'\n'</span></td></tr><tr><td class="number">7</td><td>   pop0</td></tr><tr><td class="number">8</td><td>   push %R</td></tr><tr><td class="number">9</td><td>   call <a href="http://www.delorie.com/djgpp/doc/libc/libc_517.html" target="_blank">itoa</a></td></tr><tr><td class="number">10</td><td>   pop0</td></tr><tr><td class="number">11</td><td>   push itoa_str</td></tr><tr><td class="number">12</td><td>   call print</td></tr><tr><td class="number">13</td><td>   pop0</td></tr><tr><td class="number">14</td><td>   put <span class="s">'\n'</span></td></tr><tr><td class="number">15</td><td>   hlt</td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td>fib:</td></tr><tr><td class="number">18</td><td><span class="c">// put '.'</span></td></tr><tr><td class="number">19</td><td>   cmp $<span class="n">1</span>, <span class="n">2</span></td></tr><tr><td class="number">20</td><td>   jle fibend</td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td>   sub $<span class="n">1</span>, <span class="n">1</span></td></tr><tr><td class="number">23</td><td>   push $<span class="n">1</span></td></tr><tr><td class="number">24</td><td>   call fib</td></tr><tr><td class="number">25</td><td>   mov %A, %R</td></tr><tr><td class="number">26</td><td>   pop0</td></tr><tr><td class="number">27</td><td>&#160;</td></tr><tr><td class="number">28</td><td>   sub $<span class="n">1</span>, <span class="n">1</span></td></tr><tr><td class="number">29</td><td>   push $<span class="n">1</span></td></tr><tr><td class="number">30</td><td>   call fib</td></tr><tr><td class="number">31</td><td>   mov %B, %R</td></tr><tr><td class="number">32</td><td>   pop0</td></tr><tr><td class="number">33</td><td>&#160;</td></tr><tr><td class="number">34</td><td>   add %A, %B</td></tr><tr><td class="number">35</td><td>   ret %A</td></tr><tr><td class="number">36</td><td>&#160;</td></tr><tr><td class="number">37</td><td>fibend:</td></tr><tr><td class="number">38</td><td>   ret <span class="n">1</span></td></tr></tbody></table></div></div><p>

edit2, and here&#39;s the lib.inc you see from that last example:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>FUNC getstr:</td></tr><tr><td class="number">2</td><td>MOV %A, getstr_str</td></tr><tr><td class="number">3</td><td>getstr_loop:</td></tr><tr><td class="number">4</td><td>GET %B</td></tr><tr><td class="number">5</td><td>PUT %B</td></tr><tr><td class="number">6</td><td>CMP %B, <span class="n">4</span></td></tr><tr><td class="number">7</td><td>JE exit_getstr</td></tr><tr><td class="number">8</td><td>CMP %B, <span class="s">'\n'</span></td></tr><tr><td class="number">9</td><td>JE exit_getstr</td></tr><tr><td class="number">10</td><td>MOV MEM %A, %B</td></tr><tr><td class="number">11</td><td>INC %A</td></tr><tr><td class="number">12</td><td>JMP getstr_loop</td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>exit_getstr:</td></tr><tr><td class="number">15</td><td>MOV MEM %A, <span class="n">0</span></td></tr><tr><td class="number">16</td><td>RET <span class="n">1</span></td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td>FUNC strcpy:</td></tr><tr><td class="number">19</td><td>MOV %A, $<span class="n">1</span></td></tr><tr><td class="number">20</td><td>MOV %B, $<span class="n">2</span></td></tr><tr><td class="number">21</td><td>strcpy_loop:</td></tr><tr><td class="number">22</td><td>CMP MEM %A, <span class="n">0</span></td></tr><tr><td class="number">23</td><td>JLE strcpy_exit</td></tr><tr><td class="number">24</td><td>MOV MEM %B, MEM %A</td></tr><tr><td class="number">25</td><td>INC %A</td></tr><tr><td class="number">26</td><td>INC %B</td></tr><tr><td class="number">27</td><td>JMP strcpy_loop</td></tr><tr><td class="number">28</td><td>strcpy_exit:</td></tr><tr><td class="number">29</td><td>MOV MEM %B, <span class="n">0</span></td></tr><tr><td class="number">30</td><td>RET <span class="n">1</span></td></tr><tr><td class="number">31</td><td>&#160;</td></tr><tr><td class="number">32</td><td>FUNC print:</td></tr><tr><td class="number">33</td><td>MOV %F, $<span class="n">1</span></td></tr><tr><td class="number">34</td><td>print_loop:</td></tr><tr><td class="number">35</td><td>CMP MEM %F, <span class="n">0</span></td></tr><tr><td class="number">36</td><td>JLE quit_print</td></tr><tr><td class="number">37</td><td>PUT MEM %F</td></tr><tr><td class="number">38</td><td>INC %F</td></tr><tr><td class="number">39</td><td>JMP print_loop</td></tr><tr><td class="number">40</td><td>quit_print:</td></tr><tr><td class="number">41</td><td>RET <span class="n">1</span></td></tr><tr><td class="number">42</td><td>&#160;</td></tr><tr><td class="number">43</td><td>FUNC itoa:</td></tr><tr><td class="number">44</td><td>MOV %F, $<span class="n">1</span></td></tr><tr><td class="number">45</td><td>MOV %D, <span class="n">0</span></td></tr><tr><td class="number">46</td><td>MOV %B, <span class="n">0</span></td></tr><tr><td class="number">47</td><td>MOV %A, itoa_tmp</td></tr><tr><td class="number">48</td><td>&#160;</td></tr><tr><td class="number">49</td><td>itoa_loop:</td></tr><tr><td class="number">50</td><td>MOV %C, %F</td></tr><tr><td class="number">51</td><td>MOD %C, <span class="n">10</span></td></tr><tr><td class="number">52</td><td>MOV MEM %A, %C</td></tr><tr><td class="number">53</td><td>&#160;</td></tr><tr><td class="number">54</td><td>INC %A</td></tr><tr><td class="number">55</td><td>INC %D</td></tr><tr><td class="number">56</td><td>DIV %F, <span class="n">10</span></td></tr><tr><td class="number">57</td><td>&#160;</td></tr><tr><td class="number">58</td><td>CMP %F, <span class="n">0</span></td></tr><tr><td class="number">59</td><td>JLE get_out_itoaloop</td></tr><tr><td class="number">60</td><td>CMP %D, <span class="n">11</span></td></tr><tr><td class="number">61</td><td>JLE itoa_loop</td></tr><tr><td class="number">62</td><td>&#160;</td></tr><tr><td class="number">63</td><td>get_out_itoaloop:</td></tr><tr><td class="number">64</td><td>MOV %B, itoa_str</td></tr><tr><td class="number">65</td><td>itoa_loop2:</td></tr><tr><td class="number">66</td><td>DEC %A</td></tr><tr><td class="number">67</td><td>DEC %D</td></tr><tr><td class="number">68</td><td>MOV %C, MEM %A</td></tr><tr><td class="number">69</td><td>ADD %C, <span class="s">'0'</span></td></tr><tr><td class="number">70</td><td>MOV MEM %B, %C</td></tr><tr><td class="number">71</td><td>&#160;</td></tr><tr><td class="number">72</td><td>INC %B</td></tr><tr><td class="number">73</td><td>CMP %D, <span class="n">0</span></td></tr><tr><td class="number">74</td><td>JG itoa_loop2</td></tr><tr><td class="number">75</td><td>exit_itoa:</td></tr><tr><td class="number">76</td><td>MOV MEM %B, <span class="n">0</span></td></tr><tr><td class="number">77</td><td>RET itoa_str</td></tr><tr><td class="number">78</td><td>&#160;</td></tr><tr><td class="number">79</td><td>FUNC strlen:</td></tr><tr><td class="number">80</td><td>MOV %F, $<span class="n">1</span></td></tr><tr><td class="number">81</td><td>MOV %A, <span class="n">0</span></td></tr><tr><td class="number">82</td><td>strlen_loop:</td></tr><tr><td class="number">83</td><td>CMP MEM %F, <span class="n">0</span></td></tr><tr><td class="number">84</td><td>JLE strlen_exit</td></tr><tr><td class="number">85</td><td>INC %F</td></tr><tr><td class="number">86</td><td>INC %A</td></tr><tr><td class="number">87</td><td>JMP strlen_loop</td></tr><tr><td class="number">88</td><td>&#160;</td></tr><tr><td class="number">89</td><td>strlen_exit:</td></tr><tr><td class="number">90</td><td>RET %A</td></tr><tr><td class="number">91</td><td>&#160;</td></tr><tr><td class="number">92</td><td>FUNC atoi:</td></tr><tr><td class="number">93</td><td>MOV %F, $<span class="n">1</span></td></tr><tr><td class="number">94</td><td>MOV %A, <span class="n">0</span></td></tr><tr><td class="number">95</td><td>MOV %B, <span class="n">0</span></td></tr><tr><td class="number">96</td><td>MOV %C, <span class="n">0</span></td></tr><tr><td class="number">97</td><td>MOV %D, <span class="n">1</span></td></tr><tr><td class="number">98</td><td>&#160;</td></tr><tr><td class="number">99</td><td>MOV %B, $<span class="n">1</span></td></tr><tr><td class="number">100</td><td>&#160;</td></tr><tr><td class="number">101</td><td>atoi_loop1:</td></tr><tr><td class="number">102</td><td>MOV %AESB0, MEM %F</td></tr><tr><td class="number">103</td><td>&#160;</td></tr><tr><td class="number">104</td><td><span class="c">// if end of string, exit</span></td></tr><tr><td class="number">105</td><td>CMP %AESB0, <span class="n">0</span></td></tr><tr><td class="number">106</td><td>JG lt9</td></tr><tr><td class="number">107</td><td>JMP exit_atoi_loop1</td></tr><tr><td class="number">108</td><td>&#160;</td></tr><tr><td class="number">109</td><td><span class="c">// if the current charater is greater than '9', exit</span></td></tr><tr><td class="number">110</td><td>lt9:</td></tr><tr><td class="number">111</td><td>CMP %AESB0, <span class="s">'9'</span></td></tr><tr><td class="number">112</td><td>JLE gt0</td></tr><tr><td class="number">113</td><td>JMP exit_atoi_loop1</td></tr><tr><td class="number">114</td><td>&#160;</td></tr><tr><td class="number">115</td><td><span class="c">// if the current character is less than '0', exit</span></td></tr><tr><td class="number">116</td><td>gt0:</td></tr><tr><td class="number">117</td><td>CMP %AESB0, <span class="s">'0'</span></td></tr><tr><td class="number">118</td><td>JGE go_on</td></tr><tr><td class="number">119</td><td>JMP exit_atoi_loop1</td></tr><tr><td class="number">120</td><td>&#160;</td></tr><tr><td class="number">121</td><td>go_on:</td></tr><tr><td class="number">122</td><td>INC %A</td></tr><tr><td class="number">123</td><td>INC %F</td></tr><tr><td class="number">124</td><td>JMP atoi_loop1</td></tr><tr><td class="number">125</td><td>&#160;</td></tr><tr><td class="number">126</td><td>exit_atoi_loop1:</td></tr><tr><td class="number">127</td><td>&#160;</td></tr><tr><td class="number">128</td><td>DEC %A</td></tr><tr><td class="number">129</td><td>CMP %A, <span class="n">0</span></td></tr><tr><td class="number">130</td><td>JL exit_atoi</td></tr><tr><td class="number">131</td><td>MOV %F, %B</td></tr><tr><td class="number">132</td><td>ADD %F, %A</td></tr><tr><td class="number">133</td><td>&#160;</td></tr><tr><td class="number">134</td><td>atoi_loop:</td></tr><tr><td class="number">135</td><td>&#160;</td></tr><tr><td class="number">136</td><td>CMP %A, <span class="n">0</span></td></tr><tr><td class="number">137</td><td>JL exit_atoi</td></tr><tr><td class="number">138</td><td>&#160;</td></tr><tr><td class="number">139</td><td>MOV %ABSB0, MEM %F</td></tr><tr><td class="number">140</td><td>SUB %ABSB0, <span class="s">'0'</span></td></tr><tr><td class="number">141</td><td>MUL %B, %D</td></tr><tr><td class="number">142</td><td>MUL %D, <span class="n">10</span></td></tr><tr><td class="number">143</td><td>ADD %C, %B</td></tr><tr><td class="number">144</td><td>MOV %B, <span class="n">0</span></td></tr><tr><td class="number">145</td><td>DEC %F</td></tr><tr><td class="number">146</td><td>DEC %A</td></tr><tr><td class="number">147</td><td>JMP atoi_loop</td></tr><tr><td class="number">148</td><td>&#160;</td></tr><tr><td class="number">149</td><td>exit_atoi:</td></tr><tr><td class="number">150</td><td>RET %C</td></tr><tr><td class="number">151</td><td>&#160;</td></tr><tr><td class="number">152</td><td>FUNC fopen:</td></tr><tr><td class="number">153</td><td>PUSH $<span class="n">1</span></td></tr><tr><td class="number">154</td><td>PUSH $<span class="n">2</span></td></tr><tr><td class="number">155</td><td>&#160;</td></tr><tr><td class="number">156</td><td>RET %A</td></tr><tr><td class="number">157</td><td>&#160;</td></tr><tr><td class="number">158</td><td>itoa_tmp:</td></tr><tr><td class="number">159</td><td>DB <span class="s">"             "</span></td></tr><tr><td class="number">160</td><td>&#160;</td></tr><tr><td class="number">161</td><td>itoa_str:</td></tr><tr><td class="number">162</td><td>DB <span class="s">"                       "</span></td></tr><tr><td class="number">163</td><td>&#160;</td></tr><tr><td class="number">164</td><td>getstr_str:</td></tr><tr><td class="number">165</td><td>DB <span class="s">"                                                                                          "</span></td></tr></tbody></table></div></div><p>
Yup, a mini libc <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> omg.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 00:32:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah OMG is a good expression. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> I briefly checked out the source code, but around 2100 lines is a bit to much for a casual viewing. Impressive work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Wed, 22 Nov 2006 04:58:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Needs a CRZ opcode.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Nov 2006 05:16:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> I was always a little proud of my little CHIP project. Even though its pretty dead now. I ended up writing two styles of execution loop for it, one with a while+switch, and a &quot;threaded&quot; aka &quot;computed goto&quot; &quot;loop&quot;. The computed goto code ran around 10x faster than the plain while+switch, back in the day, on my Athlon 900, or it could have been my 450 p3 (I cant recall now), I got upwards of 10 MIPS out of this VM. It could be much better if I didn&#39;t have all that &quot;smart&quot; register and fancy arg handling, and make 60x more actual instructions, but I didn&#39;t want to go there without making some &quot;generator&quot; for all the extra instruction types, which I never finished.</p><p>The second vm I made is pretty cool. It has psuedo OO support. you can set a &quot;foo.bar&quot; to a function: <i>set &quot;foo.bar&quot; &quot;somefunction&quot;</i>  call it using the &quot;extended&quot; function calling support, as: <i>foo.bar;</i> and the assembler will do <i>call &quot;somefunction&quot; &quot;foo&quot;</i>. And the &quot;second pass&quot; will attempt to turn all string references (which are looked up in a symtab hash at runtime normally), into direct symbol references (pointers to the stuff stored in the symtab, instead of a string which may need to be parsed, ie: &quot;foo.bar.baz&quot; requires the engine to split it at the dots, and then do a look up for baz in bar, and bar in foo, and foo in the global symtab...), which speeds up the engine by N times. (gotta be more than 10 but I can&#39;t recall). Oh yeah, the &quot;foo.bar&quot; syntax means look up the &quot;bar&quot; property in the &quot;foo&quot; object, and &quot;foo.bar.baz&quot; means, look up the baz property in the (possibly anon) object referenced in bar, and lookup the bar property in the foo object. I don&#39;t think i could have made it more complex &gt;:)</p><p>edit: X-G, excuse my ignorance, but what is a CRZ opcode? I&#39;ve not heard of that one. A couple google searches didn&#39;t seem to help either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 05:19:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
So it has first-class functions?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Nov 2006 05:21:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The newer of the two does yes.</p><div class="source-code snippet"><div class="inner"><pre>function doit
   set doit system.stack.pop
   print doit.value
ret
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 05:23:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nice work Moose.  <a href="http://en.wikipedia.org/wiki/Malbolge_programming_language">CRZ op rules.</a></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Yeah he needs to know assembler in that case. Can&#39;t really get why he head to implement his compiler in assembler though, but I guess it could be a good exercise if you study assembler.
</p></div></div><p>

I don&#39;t think the OP was posting about a compilation oriented assignment.  From what I&#39;ve seen here in the states, infix to postix is a standard exercise students do when studying stacks etc...  You certainly wouldn&#39;t use that method in a real compiler, you&#39;d generate assembler from the AST.</p><p>And you don&#39;t have to generate code at all.  For my little Basic thingy I&#39;m executing from the tree.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Wed, 22 Nov 2006 05:41:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How much compilers would assembler compile, if assembler would compile compilers? :-P</p><p>(Ducks)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ciro Duran)</author>
		<pubDate>Wed, 22 Nov 2006 10:07:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I don&#39;t think the OP was posting about a compilation oriented assignment. From what I&#39;ve seen here in the states, infix to postix is a standard exercise students do when studying stacks etc... You certainly wouldn&#39;t use that method in a real compiler, you&#39;d generate assembler from the AST.
</p></div></div><p>
You&#39;re probably right about the goal of the assignment. I didn&#39;t check out the code he posted. Infix to postfix is a common excercise here as well when studying stacks.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And you don&#39;t have to generate code at all. For my little Basic thingy I&#39;m executing from the tree.
</p></div></div><p>
Yeah. How is it going with that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Wed, 22 Nov 2006 12:28:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>IMO, compiling to some slim bytecode will always be more efficient runtime wise than traversing a tree. Not that its necessarily needed in all cases, but I like to brag about irrelevant things like MIPS, FLOPS and MHZ.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 12:47:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It sounds sensible to me at least. Perhaps there is also a bit more flexibility in there. As you can layer things so that you can write a new backend for some other type of format (like Java Byte Code or something).</p><p>On the other hand executing an interpreter directly from the tree is probably easier to implement.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Wed, 22 Nov 2006 17:14:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I always had this mental block with doing a direct execute interpreter. Wasn&#39;t ever able to fully grasp how to make one when I was still learning about VMs and such.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 Nov 2006 23:42:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s coming along slowly.  The method I&#39;m using is pretty simple when your just passing ints around, but when you starting adding ints OR floats, it doesn&#39;t work:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">//given a tree like:</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td>         <span class="k3">+</span></td></tr><tr><td class="number">4</td><td>       <span class="k3">/</span>   \</td></tr><tr><td class="number">5</td><td>      <span class="n">5</span>     <span class="k3">*</span></td></tr><tr><td class="number">6</td><td>          <span class="k3">/</span>   \</td></tr><tr><td class="number">7</td><td>         <span class="n">3</span>     <span class="n">9</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td><span class="c">//this is how you execute from the tree, it's just a</span></td></tr><tr><td class="number">10</td><td><span class="c">//depth first traversal:</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td><span class="k1">int</span> execNode<span class="k2">(</span>Node<span class="k3">*</span> n<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">13</td><td>    <span class="k1">switch</span><span class="k2">(</span>n-&gt;type<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">14</td><td>        <span class="k1">case</span> <span class="s">'+'</span><span class="k2">:</span></td></tr><tr><td class="number">15</td><td>            <span class="k1">return</span> <span class="k2">(</span>execNode<span class="k2">(</span>n-&gt;left<span class="k2">)</span> <span class="k3">+</span> execNode<span class="k2">(</span>n-&gt;right<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td>        <span class="k1">case</span> <span class="s">'-'</span><span class="k2">:</span></td></tr><tr><td class="number">17</td><td>            <span class="k1">return</span> <span class="k2">(</span>execNode<span class="k2">(</span>n-&gt;left<span class="k2">)</span> <span class="k3">-</span> execNode<span class="k2">(</span>n-&gt;right<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>        <span class="k1">case</span> <span class="s">'*'</span><span class="k2">:</span></td></tr><tr><td class="number">19</td><td>            <span class="k1">return</span> <span class="k2">(</span>execNode<span class="k2">(</span>n-&gt;left<span class="k2">)</span> <span class="k3">*</span> execNode<span class="k2">(</span>n-&gt;right<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>        <span class="k1">case</span> <span class="s">'/'</span><span class="k2">:</span></td></tr><tr><td class="number">21</td><td>            <span class="k1">return</span> <span class="k2">(</span>execNode<span class="k2">(</span>n-&gt;left<span class="k2">)</span> <span class="k3">/</span> execNode<span class="k2">(</span>n-&gt;right<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>        <span class="k1">case</span> INTCONST:</td></tr><tr><td class="number">23</td><td>            <span class="k1">return</span> n-&gt;int_value<span class="k2">;</span></td></tr><tr><td class="number">24</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">25</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

As you can see the exec function just returns an int.  Now I&#39;m looking into using a runtime store of some sort to pass values around.</p><p>But it&#39;s two different issues; compiling and then what you do with it.  This is a question of the execution environment.  And I&#39;m beginning to see why emitting bytecode for a virtual machines is such a good idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Thu, 23 Nov 2006 05:02:20 +0000</pubDate>
	</item>
</rss>
