Difference between revisions of "CSC103 Homework 4 Solutions Fall 2012"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <onlydft> =Problem #4= <code><pre> start: lod-c table ; get address of table in memory sto loc ; store it in loc variable. Now loc ; contains the address of ...")
 
Line 2: Line 2:
 
----
 
----
 
<onlydft>
 
<onlydft>
 +
=Problem #2=
 +
<code><pre>
 +
; Sum100 program
 +
; D. Thiebaut
 +
; Computes the sum of all the numbers between 0 and 10
 +
; and stores the result in variable sum.
 +
;
 +
 +
@0
 +
      jmp start
 +
 +
;
 +
; data section with 2 variables
 +
;
 +
counter: 100
 +
sum: 0
 +
 +
;
 +
; code section
 +
;
 +
start:
 +
 +
; sum <- counter
 +
lod counter
 +
sto sum
 +
 +
; counter <- counter - 1
 +
loop:
 +
lod counter
 +
dec
 +
dec
 +
sto counter
 +
 +
; if counter is 0, then jump out of loop
 +
jmz done
 +
 +
; sum <- sum + counter
 +
lod sum
 +
add counter
 +
sto sum
 +
 +
; go back to compute new sum
 +
jmp loop
 +
 +
; if we reach this point, then we are done with
 +
; the loop and sum should contain the result
 +
done: hlt
 +
</pre></code>
 +
 +
 
=Problem #4=
 
=Problem #4=
 
<code><pre>
 
<code><pre>

Revision as of 14:53, 11 October 2012

--D. Thiebaut 14:48, 11 October 2012 (EDT)



...