-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ52.asm
More file actions
56 lines (52 loc) · 772 Bytes
/
Q52.asm
File metadata and controls
56 lines (52 loc) · 772 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
; Solution to question no 2 from Assignment #5
msg1: dw "Please enter a number: "
x: dw 0
sum: dw 0
mainsum: dw 0
i: dw 1
j: dw 1
@1: dw 1
main:
ldc msg1
sout
din
st x
loop:
ld x
sub i ; x - i
jn finish
ld i
push; i
aloc 1 ;retVal, i
call adder; returnAdd, retVal, i
pop
add mainsum
st mainsum
dloc 1
ld i
add @1
st i
ja loop
adder:
;returnAdd, retVal, i
ld @1
subr 2
jzop finish1
ldr 2
sub @1 ; i - 1
push ;i - 1, returnAdd, retVal, i
aloc 1; retVal, i - 1, returnAdd, retVal, i
call adder ;returnAdd, retVal, i - 1, returnAdd, retVal, i
pop ; i-1, returnAdd, retVal, i
dloc 1 ; returnAdd, retVal, i
addr 2
str 1
ret
finish1:
ldr 2
str 1
ret
finish:
ld mainsum
dout
halt