Difference between revisions of "CSC103 Assembly Language Exercises and Solutions"
(→LOD-C 1) |
|||
Line 3: | Line 3: | ||
: initialize the contents of several variables to 0 | : initialize the contents of several variables to 0 | ||
<code><pre> | <code><pre> | ||
+ | ; 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 | ||
</pre></code> | </pre></code> | ||
Line 9: | Line 24: | ||
;Exercise 2 | ;Exercise 2 | ||
: increment a counter | : increment a counter | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
;Exercise 3 | ;Exercise 3 | ||
: compute sum of 3 variables | : compute sum of 3 variables | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
=LOD-I 10/STO-I 10= | =LOD-I 10/STO-I 10= | ||
Line 16: | Line 35: | ||
'Exercise 4: | 'Exercise 4: | ||
:create an index and use it to sum up the same 3 variables | :create an index and use it to sum up the same 3 variables | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
=JMP instruction and labels= | =JMP instruction and labels= | ||
;Exercise 5 | ;Exercise 5 | ||
: create an infinite loop (incrementing a variable, for example) | : create an infinite loop (incrementing a variable, for example) | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
+ | |||
+ | |||
;Exercise 6 | ;Exercise 6 | ||
: create an infinite loop that clears the memory starting at 10 | : create an infinite loop that clears the memory starting at 10 | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
+ | |||
+ | |||
;Exercise 7 | ;Exercise 7 | ||
: why does the program of Exercise 6 stop? | : why does the program of Exercise 6 stop? | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
=JMZ= | =JMZ= | ||
Exercise 8 | Exercise 8 | ||
: write a loop that loops 10 times (use a counter) | : write a loop that loops 10 times (use a counter) | ||
+ | <code><pre> | ||
+ | </pre></code> | ||
+ | |||
Exercise 9 | Exercise 9 | ||
: write a loop that stores 55 in the memory locations between 15 and 30 | : write a loop that stores 55 in the memory locations between 15 and 30 | ||
+ | <code><pre> | ||
+ | </pre></code> |
Revision as of 11:29, 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
- Exercise 2
- increment a counter
- Exercise 3
- compute sum of 3 variables
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