Difference between revisions of "CSC103 2011 Homework 3 Solution"
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] 10:57, 25 February 2011 (EST) | --[[User:Thiebaut|D. Thiebaut]] 10:57, 25 February 2011 (EST) | ||
---- | ---- | ||
− | + | <onlydft> | |
=Problem #1= | =Problem #1= | ||
* Here are two options provided by Kristina. | * Here are two options provided by Kristina. | ||
Line 112: | Line 112: | ||
<br /> | <br /> | ||
=Problem #3= | =Problem #3= | ||
+ | <code><pre> | ||
+ | ; Problem #3 | ||
+ | ; Julia Fernandez | ||
+ | ; (Edited by D. Thiebaut) | ||
+ | ; Computes the sum of all the numbers between | ||
+ | ; 1 and 10. | ||
+ | |||
+ | ; The accumulator will find the sum of the numbers 1-10, | ||
+ | ; beginning with ;10 and adding backwards (so 10+9+8…). | ||
+ | |||
+ | Start: Lod-c 10 ; Store 10 to the location “Index” | ||
+ | Sto Index | ||
+ | Lod-c 0 ; Store 0 to the location “Sum” | ||
+ | Sto Sum | ||
+ | |||
+ | |||
+ | ; I will now create a loop that counts backwards from zero. | ||
+ | ; As it counts down, it adds whatever number it’s on to the | ||
+ | ; total at location “Sum”. | ||
+ | ; Once the counter has reached zero, the program will stop. | ||
+ | |||
+ | Loop: Lod Sum ; Load data at address Sum into acc | ||
+ | Add Index ; Add data at address Index to Sum | ||
+ | Sto Sum ; Store result in Sum | ||
+ | Lod Index ; Load data at address Index into acc | ||
+ | Dec ; acc = acc-1 | ||
+ | Jmz Done ; If acc=0, then skip to address Done | ||
+ | Sto Index ; If acc does not equal 0, store number in acc in Index | ||
+ | Jmp Loop ; Jump to beginning of loop | ||
+ | |||
+ | Done: HLT ; If acc=0, program stops | ||
+ | |||
+ | @15 | ||
+ | Index: data | ||
+ | Sum: 0 | ||
+ | |||
+ | |||
+ | </pre></code> | ||
=Problem #4= | =Problem #4= | ||
Line 144: | Line 182: | ||
</pre></code> | </pre></code> | ||
− | + | </onlydft> | |
<br /> | <br /> | ||