forked from uva-cs/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-summation.ibcm
35 lines (35 loc) · 956 Bytes
/
array-summation.ibcm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
C00A 000 jmp start skip around the variables
0000 001 i dw 0 int i
0000 002 s dw 0 int s
0000 003 a dw 0 int a[]
0000 004 n dw 0
0000 005 zero dw 0
0001 006 one dw 1
5000 007 adit dw 5000
0000 008 leave space for changes
0000 009
1000 00A start readH read array address
4003 00B store a
1000 00C readH read array size
4004 00D store n
3005 00E load zero i = 0; s = 0;
4001 00F store i
4002 010 store s
3004 011 loop load n if (i >= N) goto xit
6001 012 sub i
E020 013 jmpl xit
D020 014 jmpe xit
3007 015 load adit form the instruction to add a[i]
5003 016 add a
5001 017 add i
401A 018 store doit plant the instruction into the program
3002 019 load s s += a[i]
0000 01A doit dw 0
4002 01B store s
3001 01C load i i += 1
5006 01D add one
4001 01E store i
C011 01F jmp loop goto loop
3002 020 xit load s print s
1800 021 printH
0000 022 halt