Difference between revisions of "CSC103 Homework3 Solutions, 2012"
(→Assembly Language) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] 14:11, 28 February 2012 (EST) | --[[User:Thiebaut|D. Thiebaut]] 14:11, 28 February 2012 (EST) | ||
---- | ---- | ||
+ | <onlydft> | ||
=Wiki Page= | =Wiki Page= | ||
Line 13: | Line 14: | ||
* There were several ways to write the program. Here's one below that uses different instructions. | * There were several ways to write the program. Here's one below that uses different instructions. | ||
* Importantly, you have to make sure that the address you specify for the data with the '''@''' symbol is '''above''' the address of the last instruction, which is a '''hlt''' instruction. If you do not, then your program overwrites the instructions at the end of your program and you have a program with a '''major''' bug on your hands! | * Importantly, you have to make sure that the address you specify for the data with the '''@''' symbol is '''above''' the address of the last instruction, which is a '''hlt''' instruction. If you do not, then your program overwrites the instructions at the end of your program and you have a program with a '''major''' bug on your hands! | ||
− | + | * Note: in the program below, whatever follows a semicolon is a comment, something that the processor will not execute! | |
+ | <br /> | ||
<code><pre> | <code><pre> | ||
; Assembly language program that initializes 10 variables with | ; Assembly language program that initializes 10 variables with | ||
; a specific series of integers: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19. | ; a specific series of integers: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19. | ||
; | ; | ||
− | start: lod-c 1 | + | start: lod-c 1 ;AC <- 1 |
− | sto var1 | + | sto var1 ;var1 <- AC which is 1 |
− | add-c 2 | + | add-c 2 ;AC <- AC + 2. AC now contains 3 |
− | sto var2 | + | sto var2 ;var2 <- AC, or 3 |
− | lod-c 5 | + | lod-c 5 ;AC <- 5 |
− | sto var3 | + | sto var3 ;var3 <- 5 |
− | add-c 2 | + | add-c 2 ;AC <- 5+ 2 = 7 |
− | sto var4 | + | sto var4 ;var4 <- 7 |
− | inc | + | inc ;AC <- AC + 1 = 8 |
− | inc | + | inc ;AC <- AC + 1 = 9 |
− | sto var5 | + | sto var5 ;var5 <- 9 |
− | add-c 2 | + | add-c 2 ;AC <- 11 |
− | sto var6 | + | sto var6 ;var6 <- 11 |
− | add-c 2 | + | add-c 2 ;AC <- 13 |
− | sto var7 | + | sto var7 ;var7 <- 13 |
− | add-c 2 | + | add-c 2 ;AC <- 15 |
− | sto var8 | + | sto var8 ;var8 <- 13 |
− | add-c 2 | + | add-c 2 ;AC <- 17 |
− | sto var9 | + | sto var9 ;var9 <- 17 |
− | add-c 2 | + | add-c 2 ;AC <- 19 |
− | sto var10 | + | sto var10 ;var10 <- 19 |
− | hlt | + | hlt ;program stops |
+ | |||
+ | |||
@30 | @30 | ||
− | var1: | + | var1: 0 |
− | var2: | + | var2: 0 |
− | var3: | + | var3: 0 |
− | var4: | + | var4: 0 |
− | var5: | + | var5: 0 |
− | var6: | + | var6: 0 |
− | var7: | + | var7: 0 |
− | var8: | + | var8: 0 |
− | var9: | + | var9: 0 |
− | var10: | + | var10: 0 |
</pre></code> | </pre></code> | ||
Line 62: | Line 66: | ||
<br /> | <br /> | ||
− | + | </onlydft> | |
<br /> | <br /> | ||