Difference between revisions of "CSC103 Assembly Language Exercises and Solutions"
(→LOD 10/STO 10) |
(→LOD 10/STO 10) |
||
Line 54: | Line 54: | ||
start: lod var1 ; get var1 in acc | start: lod var1 ; get var1 in acc | ||
− | + | add var2 ; add var2 to acc | |
− | + | add var3 ; add var3 to acc | |
− | + | sto sum ; store acc into sum | |
− | + | hlt | |
@10 | @10 |
Revision as of 11:36, 20 February 2011
LOD-C 1
- Exercise 1
- initialize the contents of several variables to 0
; Exercise 1
; D. Thiebaut
; Initialize the contents of several variables
; to 55
start:
lod-c 55 ; put 0 in acc
sto var1 ; store acc in var1
sto var2 ; store acc in var2
sto var3 ; store acc in var3
hlt
@10 ; the data section starts here
var1: data
var2: data
var3: data
LOD 10/STO 10
- Exercise 2
- increment a counter
; Exercise 2
; D. Thiebaut
; A program that sets a counter to 0
; and then increments it
;
start: lod-c 0 ; first initialize the counter to 0
sto counter
; increment counter
lod counter ; get counter in acc
add-c 1 ; add 1 to acc
sto counter ; store acc in counter
hlt
@10
counter: data
- Exercise 3
- compute sum of 3 variables
; Exercise 3
; D. Thiebaut
; Compute the sum of 3 variables
; and stores it into a 4th variable called
; sum.
start: lod var1 ; get var1 in acc
add var2 ; add var2 to acc
add var3 ; add var3 to acc
sto sum ; store acc into sum
hlt
@10
var1: 12
var2: 5
var3: 3
sum: 0
LOD-I 10/STO-I 10
'Exercise 4:
- create an index and use it to sum up the same 3 variables
JMP instruction and labels
- Exercise 5
- create an infinite loop (incrementing a variable, for example)
- Exercise 6
- create an infinite loop that clears the memory starting at 10
- Exercise 7
- why does the program of Exercise 6 stop?
JMZ
Exercise 8
- write a loop that loops 10 times (use a counter)
Exercise 9
- write a loop that stores 55 in the memory locations between 15 and 30