Difference between revisions of "CSC103 Homework3 Solutions, 2012"
(→Assembly Language) |
(→Assembly Language) |
||
Line 44: | Line 44: | ||
@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> |
Revision as of 14:21, 28 February 2012
--D. Thiebaut 14:11, 28 February 2012 (EST)
Wiki Page
General Comments:
- You had to answer the questions from the lab handout
- You had to use the different wiki features listed in the homework
- You had to write a paragraph for each main component found.
- If you closed up the PC at the end of the lab, you got extra credits in the form of 1/3 point that was added to the final grade (pink grade).
Assembly Language
- 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!
- Note: in the program below, whatever follows a semicolon is a comment, something that the processor will not execute!
; Assembly language program that initializes 10 variables with
; a specific series of integers: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19.
;
start: lod-c 1 ;AC <- 1
sto var1 ;var1 <- AC which is 1
add-c 2 ;AC <- AC + 2. AC now contains 3
sto var2 ;var2 <- AC, or 3
lod-c 5 ;AC <- 5
sto var3 ;var3 <- 5
add-c 2 ;AC <- 5+ 2 = 7
sto var4 ;var4 <- 7
inc ;AC <- AC + 1 = 8
inc ;AC <- AC + 1 = 9
sto var5 ;var5 <- 9
add-c 2 ;AC <- 11
sto var6 ;var6 <- 11
add-c 2 ;AC <- 13
sto var7 ;var7 <- 13
add-c 2 ;AC <- 15
sto var8 ;var8 <- 13
add-c 2 ;AC <- 17
sto var9 ;var9 <- 17
add-c 2 ;AC <- 19
sto var10 ;var10 <- 19
hlt ;program stops
@30
var1: 0
var2: 0
var3: 0
var4: 0
var5: 0
var6: 0
var7: 0
var8: 0
var9: 0
var10: 0
Timing Analysis
- If the processor runs at 3 GHz, it executes 3,000,000,000 cycles in 1 second.
- The processor executes 1 instruction each cycle
- The program above contains 22 instructions
- It will take the processor 22 cycles to execute our program
- In terms of time, this will be 22 * 1 sec / 3,000,000,000 = 22/3 10^-9 = 7 nanoseconds, approximately, or 7 billionth of a second.