-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoblig2_LMC-programmering
62 lines (50 loc) · 1.45 KB
/
oblig2_LMC-programmering
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
57
58
59
60
61
62
INP //input
STA n //n = input
LDA v0 //konstanten 0
STA sum //sum = 0
loop LDA n //n hentes
BRZ psum //while n != 0
sub v1 //n -= 1
STA n //n lagres
INP //input
ADD sum //sum += sum
STA sum //sum lagres
BRA loop //gjentar loop
psum LDA sum //n = 0, henter sum
OUT //print(sum)
mod LDA sum //sum hentes
BRZ pos //if sum != 0, printer "par"
SUB v2 //sum -= 2
STA sum //sum lagres
BRP mod //while sum >= 0, gjentas mod
BRA neg //if sum < 0, printer "odd"
pos LDA ptxt //henter "DAT X"
BRZ done //if "DAT 0", avslutter
OTC //print(DAT x)
LDA pos //henter minneadresse til "DAT X"
add v1 //øker minneadresse med 1
STA pos //Lagrer "DAT X" = pos
BRA pos //while not "DAT 0"
neg LDA ntxt //Samme logikk som pos-loop
BRZ done
OTC
LDA neg
add v1
STA neg
BRA neg
done HLT //Ferdig
n DAT
sum DAT
v0 DAT 0
v1 DAT 1
v2 DAT 2
ptxt DAT 10 // "\n"
DAT 112 // "p"
DAT 97 // "a"
DAT 114 // "r"
DAT 0
ntxt DAT 10 // "\n"
DAT 111 // "o"
DAT 100 // "d"
DAT 100 // "d"
DAT 0