
Writing AVR Programs Write the program in C, then translate to AVR. http://tinyurl.com/avrassembler<p>
<font face="utopia,times"><font size="6">Example: sum of first 4 integers.<tt><pre>sum = 0;
for (i = 1; i <= 4; ++i)
sum += i*i;
</pre></tt>
can be translated to
<tt><pre>sum = 0;
i = 1;
loop:
if (i == 5) goto end;;
sum = sum + i;
i = i + 1;
goto loop;
end:
</pre></tt>
can be translated to
<tt><pre>; sum in R16
; i in R17
; R18,R19 used for temporary values
LDI R16, 0
LDI R17, 1
LDI R18, 5
SUB R18, R17
BRBS 1, 22
ADD R16, R17
LDI R19, 1
ADD R17, R19
JMP 2
SLEEP
</pre></tt>
</font></font></p> 
<pre>
(define (eval exp env)
(cond ((selfevaluating? exp) exp)
((variable? exp) (lookupvariablevalue exp env))
((quoted? exp) (textofquotation exp))
((assignment? exp) (evalassignment exp env))
((definition? exp) (evaldefinition exp env))
((if? exp) (evalif exp env))
((lambda? exp)
(makeprocedure (lambdaparameters exp)
(lambdabody exp)
env))
((begin? exp)
(evalsequence (beginactions exp) env))
((cond? exp) (eval (cond>if exp) env))
((application? exp)
(apply (eval (operator exp) env)
(listofvalues (operands exp) env)))
(else
(error "Unknown expression type — EVAL" exp))))
</pre>
<ul>
<li>http://mitpress.mit.edu/sicp/fulltext/book/bookZH26.html</li>
</ul> 
<xmp>
// Regular Expressionsfunction main()
{
var re = /(w+)(s+)(w+)/;
var out = input.match(re);
for(i = 0;i < out.length;i++) {
print(i + " = [" + out[i] + "]n");
}
}
</xmp>
<blockquote>
<ul>
<li>There is a pseudofunction called "print()" (not part of javaScript) that allows data to be placed in the output window. See examples for its use.</li>
</ul>
</blockquote> 
<blockquote>
We want to write a function that generates accumulators– a
function that takes a number n, and
returns a function that takes another number i and
returns n incremented by i.
</blockquote>
<h3>JavaScript</h3>
<xmp>
function foo(n) {
return function (i) {
return n += i } }
</xmp>
<h3>Scheme</h3>
<xmp>
(define (foo n)
(lambda (i) (set! n (+ n i)) n))
</xmp>
<h2>Try</h2>
<h3><a href="http://www.arachnoid.com/javascript/interactiveJavaScript.html">JavaScript</a></h3>
<xmp>
function main() {
function foo (n) {
return function (i) {
return n += i } } ;
a = foo(5);
print(a(1));
print("n");
print(a(4));
}</xmp>
<h3><a href="http://www.bluishcoder.co.nz/jsscheme/">Scheme</a></h3>
<xmp>
(define (foo n)
(lambda (i) (set! n (+ n i)) n))
(define a (foo 5))
(a 1)
(a 4)
</xmp>
<ul>
<li>via Paul Graham's <a href="http://www.paulgraham.com/icad.html">Revenge of the Nerds</a></li>
</ul>
links for 20090516
May 17, 2009
Advertisements
Leave a Reply